delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/02/18/22:03:50

From: cgf AT bbc DOT com (Christopher Faylor)
Subject: Re: The alleged newlib/libc/stdio/fdopen.c bug
18 Feb 1998 22:03:50 -0800 :
Message-ID: <EoLv2I.DH0.cygnus.cygwin32.developers@bbc.com>
References: <01BD200C DOT EF072080 AT gater DOT krystalbank DOT msk DOT ru>
Reply-To: cgf AT bbc DOT com
To: cygwin32-developers AT cygnus DOT com

I don't know if this helps, but according to the "Single UNIX Specification"
the "a" option to fdopen should behave the same way as the "a" option to
fopen:

    Opening a file with append mode (a as the first character in the mode
    argument) causes all subsequent writes to the file to be forced to the
    then current end-of-file, regardless of intervening calls to fseek().

Here is the expected behavior for O_APPEND:

    O_APPEND
	If set, the file offset will be set to the end of the file prior to
	each write.

I'd be happier if the standard specifically addressed the "a" behavior but
it seems to imply that if a fd is opened with "a" mode it should always
seek to the end on every write.

In article <199802190107 DOT RAA09492 AT skaro DOT cygnus DOT com>,
Geoffrey Noer  <noer AT cygnus DOT com> wrote:
>A while ago, Sergey, Ian, and I had some back and forth about an
>alleged fdopen() bug.  Following is the last mail on the subject.
>I've appended the latest version of the patch for feedback.
>
>Geoff
>
>Sergey Okhapkin wrote:
>> 
>> Geoffrey Noer wrote:
>> > Ian suggests the following:
>> >
>> >   if ((oflags & O_APPEND)
>> > #ifdef F_GETFL
>> >        && !(fdflags & O_APPEND)
>> > #endif
>> >      )
>> >     fp->_flags |= __SAPP;
>> >
>> > Look right?
>> 
>> I'm not sure. When O_APPEND is set, we have to seek to end of file on 
>> fdopen() call. When __SAPP is set, _every_ write call seeks to eof before 
>> write! Is it a correct behavior for O_APPEND? BTW, where fdflags variable 
>> is defined?
>
>-------------------------------- patch -----------------------------
>
>Index: fdopen.c
>===================================================================
>RCS file: /cvs/cvsfiles/devo/newlib/libc/stdio/fdopen.c,v
>retrieving revision 1.11
>diff -c -p -r1.11 fdopen.c
>*** fdopen.c	1993/11/04 01:24:25	1.11
>--- fdopen.c	1998/02/19 01:04:06
>*************** PORTABILITY
>*** 38,43 ****
>--- 38,44 ----
>  */
>  
>  #include <sys/types.h>
>+ #include <sys/fcntl.h>
>  
>  #include <stdio.h>
>  #include <errno.h>
>*************** _DEFUN (_fdopen_r, (ptr, fd, mode),
>*** 54,59 ****
>--- 55,63 ----
>  {
>    register FILE *fp;
>    int flags, oflags;
>+ #ifdef F_GETFL
>+   int fdflags, fdmode;
>+ #endif
>  
>    if ((flags = __sflags (ptr, mode, &oflags)) == 0)
>      return 0;
>*************** _DEFUN (_fdopen_r, (ptr, fd, mode),
>*** 78,86 ****
>     * does not have O_APPEND bit set, assert __SAPP so that
>     * __swrite() will lseek to end before each write.
>     */
>  #ifdef F_GETFL
>!   if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
>  #endif
>      fp->_flags |= __SAPP;
>    fp->_file = fd;
>    fp->_cookie = (_PTR) fp;
>--- 82,92 ----
>     * does not have O_APPEND bit set, assert __SAPP so that
>     * __swrite() will lseek to end before each write.
>     */
>+   if ((oflags & O_APPEND)
>  #ifdef F_GETFL
>!        && !(fdflags & O_APPEND)
>  #endif
>+       )
>      fp->_flags |= __SAPP;
>    fp->_file = fd;
>    fp->_cookie = (_PTR) fp;


-- 
http://www.bbc.com/	cgf AT bbc DOT com			"Strange how unreal
VMS=>UNIX Solutions	Boston Business Computing	 the real can be."

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019