Re: Writing to beginning of file?

From: Bigdakine (bigdakine_at_aol.comGetaGrip)
Date: 07/29/04


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."



Relevant Pages

  • Re: Dons blog
    ... >overlap, but the lack of compression, the accumulated debris points to ... Why would the accumulation of an accretionary wedge indicate override? ... Dr. Stuart A. Weinstein ... "Creationists aren't impervious to Logic: ...
    (sci.geo.geology)
  • Re: An Open Letter to PRESIDENT BUSH
    ... Halliburton were as, if not more, important then your son's body armour. ... Dr. Stuart A. Weinstein ... "Creationists aren't impervious to Logic: ...
    (sci.geo.geology)
  • Re: Self-styled quake predictors alert causes panic
    ... >your particular value system when the truth is that you regard Americans ... so that you can feel better about your hate. ... Dr. Stuart A. Weinstein ... "Creationists aren't impervious to Logic: ...
    (sci.geo.geology)
  • Re: Earth expansion? - NEW parameters for discussion: "Geo-Biblical
    ... George … you're not content to spread your smears in the one ... >quite adequate pre-existing original thread, instead you felt you had to ... Dr. Stuart A. Weinstein ... "Creationists aren't impervious to Logic: ...
    (sci.geo.geology)
  • Re: RepRaps and RepStraps
    ... For those who have not yet heard of RepRap, ... (Warning: creationists may wish to avoid the ...
    (comp.arch.embedded)