Subject: Re: Lseek'ing backwards with SEEK_CUR?
To: None <email@example.com>
From: Charles M. Hannum <firstname.lastname@example.org>
Date: 12/14/1994 03:45:14
Is lseek'ing backwards with SEEK_CUR supported, or expected to work?
I have a program that writes out records to a file, sometimes needing
to insert them in the middle of the file. Invariably, this program
will close the file at some point, resulting in a *HUGE* file that's
backfiled with zeros.
The program does this seeking about like this:
lseek(fd, - RECSIZE, SEEK_CUR)
It sounds like you don't have a prototype (or have an incorrect one)
in scope, so the offset is being passed as 32 bits. The second
argument needs to be `off_t'.
*EITHER* way, inserting printf's that indicate current file positions
[by means of printf("%qd", lseek(fd, 0, SEEK_CUR))] indicate that the
file pointer is in the correct place.
Again, if you don't have a prototype, the return value will be taken
as 32 bits, plus whatever 32 bits of junk happens to be on the stack