Re: Writing to beginning of file?
From: Bigdakine (bigdakine_at_aol.comGetaGrip)
Date: 07/29/04
- Next message: Pascal Bourguignon: "Re: Writing to beginning of file?"
- Previous message: Roland Mainz: "Re: In which Solaris version 'typedef long long time_t;' ??"
- In reply to: Pascal Bourguignon: "Re: Writing to beginning of file?"
- Next in thread: Pascal Bourguignon: "Re: Writing to beginning of file?"
- Reply: Pascal Bourguignon: "Re: Writing to beginning of file?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Jul 2004 23:45:50 GMT
>Subject: Re: Writing to beginning of file?
>From: Pascal Bourguignon spam@thalassa.informatimago.com
>Date: 7/28/04 7:36 AM Hawaiian Standard Time
>Message-id: <87isc8825z.fsf@thalassa.informatimago.com>
>
>Rich Teer <rich.teer@rite-group.com> writes:
>
>> On Wed, 28 Jul 2004, Bigdakine wrote:
>>
>> > Is there a way in C to add records to the beginning of file, as
>> > opposed to the end?
>> >
>> > Sure there is the sledge hammer approach,
>> >
>> > where I could write the new record to a file and
>> >
>> > system( "cat new_record file > temp; mv temp file")
>> >
>> > Is there something more elegant? I though about opening the file
>> > and doing a seek(0), but I figure all that will do then is
>> > overwrite the first x number of bytes.
>>
>> Something cunning involving sendfilev() and rename() comes to mind,
>> but it doesn't avoid the temporary file problem.
>
>Because this is not a problem of C, shell or language in general, but
>a problem of file system. There is no notion of negative file
>position, so you cannot write before file position 0.
>
>
>If you had been more far-sighted, you could have started to write in
>your file for example at position start=0x1000000, and now you could
>just seek at some position start-size to write size byte.
>
>Of course, all the programs that use this file would have to know
>where the current start of file is. A convenient way to do it, is to
>add a header at the physical start of the file indicating the current
>virtual start of file.
>
>Once you've done that, and given you're telling us that you've got
>"records",
That was loose fingers ony part. The entries in the file do not all have the
same length. Although I can consider making them all the same length via
padding.
<rest of info>
Thanks for the responses.
Stuart
Dr. Stuart A. Weinstein
Ewa Beach Institute of Tectonics
"To err is human, but to really foul things up requires a creationist"
"Creationists aren't impervious to Logic: They're oblivious to it."
- Next message: Pascal Bourguignon: "Re: Writing to beginning of file?"
- Previous message: Roland Mainz: "Re: In which Solaris version 'typedef long long time_t;' ??"
- In reply to: Pascal Bourguignon: "Re: Writing to beginning of file?"
- Next in thread: Pascal Bourguignon: "Re: Writing to beginning of file?"
- Reply: Pascal Bourguignon: "Re: Writing to beginning of file?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|