Date: Mon, 29 Jun 1998 14:41:10 -0700 From: "Ronald F. Guilmette" <rfg@monkeys.com> To: To: ; Cc: Linus Torvalds <torvalds@transmeta.com> Subject: Unexpected lseek(2) non-feature Message-ID: <4526.899156470@monkeys.com>
next in thread | raw e-mail | index | archive | help
Is there some sort of an obscure rule somewhere that says that you cannot
use lseek to pre-extend a file that you have just now opened/created via
a call to open(2) with the O_CREAT option?
The following trivial program fails in exactly the same way on both Linux
(2.0.34) and FreeBSD (2.2.6) although I will be damned if I can understand
why.
It appears that if I open/create the file, and then close it again and
then reopen it, that the lseek will work then, although why I should have
to go through all of that extra work before I am allowed to pre-extend the
file (using lseek) is beyond me.
-- rfg
P.S. Looking at POSIX 1003.1b-1993, I don't see anything which mandates
this very odd behavior. Quite the contrary, POSIX 1003.1b-1993 says ``The
lseek(2) function shall allow the file offset to be set beyond the end of
existing data in the file...''
============================================================================
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
static char const *filename = "datafile.dat";
int
main (void)
{
register int fd;
unlink (filename); /* Just in case. */
if ((fd = open (filename, O_RDWR | O_CREAT, 0600)) == -1)
{
fprintf (stderr, "Unable to create file `%s': %s\n",
filename, strerror (errno));
return 1;
}
if (lseek (fd, SEEK_SET, 16384) == -1)
{
fprintf (stderr, "Unable to lseek file `%s': %s\n",
filename, strerror (errno));
return 1;
}
return 0;
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4526.899156470>
