From: noer AT cygnus DOT com (Geoffrey Noer) Subject: The alleged newlib/libc/stdio/fdopen.c bug 18 Feb 1998 17:18:34 -0800 Message-ID: <199802190107.RAA09492.cygnus.cygwin32.developers@skaro.cygnus.com> References: <01BD200C DOT EF072080 AT gater DOT krystalbank DOT msk DOT ru> Content-Type: text To: cygwin32-developers AT cygnus DOT com 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 + #include #include #include *************** _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;