Subject: Lseek'ing backwards with SEEK_CUR?
To: None <>
From: Rafal Boni <>
List: current-users
Date: 12/14/1994 01:33:04
	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)

	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);

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

					Any comments appreciated,

+--------------------------------------------------------+ +------------------+
| In search of the stress-strain relationship governing  |/|       Rafal Boni |
| students of mechanics... Experimentally.               |\| |
+--------------------------------------------------------+ +------------------+