From owner-freebsd-bugs Tue Nov 10 00:30:04 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id AAA25473 for freebsd-bugs-outgoing; Tue, 10 Nov 1998 00:30:04 -0800 (PST) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id AAA25414 for ; Tue, 10 Nov 1998 00:29:59 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id AAA25413; Tue, 10 Nov 1998 00:30:02 -0800 (PST) Date: Tue, 10 Nov 1998 00:30:02 -0800 (PST) Message-Id: <199811100830.AAA25413@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.ORG From: Bruce Evans Subject: Re: bin/8518: freopen() in append mode followed by ftell() gives strange results Reply-To: Bruce Evans Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/8518; it has been noted by GNATS. From: Bruce Evans To: Arjan.deVet@adv.iae.nl, freebsd-gnats-submit@FreeBSD.ORG Cc: sthaug@nethelp.no Subject: Re: bin/8518: freopen() in append mode followed by ftell() gives strange results Date: Tue, 10 Nov 1998 19:25:11 +1100 >During testing INN 2.2beta I discovered a possible 'bug' in the >freopen() call when used with "a" (append mode). The first ftell() >call always give 0 (irrespective of the current file length) and >subsequent writes to the file ftell() does not tell the current >write position in the file but the number of bytes written. This seems to be only a ``bug''. POSIX.1-1990 says: "If the stream is opened in append mode or if the O_APPEND flag is set as a consequence of dealing with other handles on the file, the result of ftell() on that stream is unspecified". >>How-To-Repeat: >#include >#include > >main () { > FILE *f, *g; > long i; > > g = fopen("/tmp/test", "a"); > f = freopen("/tmp/test", "a", g); > i = ftell(f); > printf("%d\n", i); > fprintf(f, "test"); > i = ftell(f); > printf("%d\n", i); > fclose(f); >} > >Create empty /tmp/test file and run the program three times. Each >time it will print 0 and 4. BSD/OS prints 0 4, 0 8 and 0 12. Solaris >and Linux print 0 4, 4 8 and 8 12. The BSD/OS behaviour is the least surprising. The initial offsets of zero may even be required (if no other process writes to the file). POSIX.1 specifies fopen() to just use open(), and freopen() to do much the same thing as fopen(). Therefore, the initial offsets at the file descriptor level are zero, and for "a+" mode, an initial read would start at the beginning of the file. Only the fuzzy specification of permits the initial offsets at the stream level to be nonzero. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message