Subject: Re: Lseek'ing backwards with SEEK_CUR?
To: Rafal Boni <firstname.lastname@example.org>
From: Frank van der Linden <email@example.com>
Date: 12/14/1994 12:45:15
Rafal Boni writes:
> 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.
> lseek(fd, - RECSIZE, SEEK_CUR)
> If I replace that with the following two lines of code, life seems
> much better: [ie, the file is correct size, etc.]
> curpos = lseek(fd, 0, SEEK_CUR);
> lseek(fd, curpos - RECSIZE, SEEK_SET);
Have you included unistd.h for an lseek prototype? It seems like
curpos - RECSIZE is succeeding, because curpos may be an off_t var,
so the subtraction result is fine, but just -RECSIZE may fail, because
the compiler would make that into a 32bit constant, not 64bit.