From owner-freebsd-questions Mon Jun 29 14:41:29 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA15316 for freebsd-questions-outgoing; Mon, 29 Jun 1998 14:41:29 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from eagle.ns.net (root@eagle.ns.net [204.75.146.20]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA15298 for ; Mon, 29 Jun 1998 14:41:16 -0700 (PDT) (envelope-from rfg@monkeys.com) Received: from monkeys.com (rfg.ns.net [207.159.10.82]) by eagle.ns.net (8.8.5/8.8.5) with ESMTP id OAA23148; Mon, 29 Jun 1998 14:41:10 -0700 (PDT) Received: from monkeys.com (localhost [127.0.0.1]) by monkeys.com (8.8.8/8.8.5) with ESMTP id OAA04528; Mon, 29 Jun 1998 14:41:10 -0700 To: To: ; Cc: Linus Torvalds Subject: Unexpected lseek(2) non-feature Date: Mon, 29 Jun 1998 14:41:10 -0700 Message-ID: <4526.899156470@monkeys.com> From: "Ronald F. Guilmette" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 #include #include #include 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