Mail Archives: djgpp-workers/1998/06/01/12:49:24
Somebody complained that fflush doesn't behave like ANSI mandates when
its argument is a NULL pointer. Here's a patch (and correction of a typo
in _fwalk's docs, while I was at that):
*** src/libc/ansi/stdio/fflush.c~0 Fri Mar 22 20:14:40 1996
--- src/libc/ansi/stdio/fflush.c Fri May 29 19:20:20 1998
***************
*** 2,7 ****
--- 2,8 ----
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
+ #include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
*************** fflush(FILE *f)
*** 14,19 ****
--- 15,32 ----
{
char *base;
int n, rn;
+
+ if (f == NULL)
+ {
+ int e = errno;
+
+ errno = 0;
+ _fwalk((void (*)(FILE *))fflush);
+ if (errno)
+ return EOF;
+ errno = e;
+ return 0;
+ }
f->_flag &= ~_IOUNGETC;
if ((f->_flag&(_IONBF|_IOWRT))==_IOWRT
*** src/libc/ansi/stdio/fflush.t~0 Mon Jul 10 05:39:40 1995
--- src/libc/ansi/stdio/fflush.txh Fri May 29 19:33:00 1998
*************** int fflush(FILE *file);
*** 9,21 ****
@subheading Description
! This function causes any unwritten buffered data to be written out to
! the given @var{file}. This is useful in cases where the output is line
! buffered and you want to write a partial line.
@subheading Return Value
! Zero on success, -1 on error.
@subheading Example
--- 9,34 ----
@subheading Description
! If @var{file} is not a @code{NULL} pointer, this function causes any
! unwritten buffered data to be written out to the given @var{file}. This
! is useful in cases where the output is line buffered and you want to
! write a partial line.
!
! If @var{file} is a @code{NULL} pointer, @code{fflush} writes any
! buffered output to all files opened for output.
!
! Note that @code{fflush} has no effect for streams opened for reading
! only. Also note that the operating system can further buffer/cache
! writes to disk files; a call to @code{fsync} (@pxref{fsync}) or
! @code{sync} (@pxref{sync}) is typically required to actually deliver
! data to the file(s).
@subheading Return Value
! Zero on success, -1 on error. When called with a @code{NULL} pointer,
! -1 will be returned if an error happened while flushing some of the
! streams (but @code{fflush} will still try to flush all the rest before
! it returns).
@subheading Example
*** src/docs/kb/wc202.~12 Sat May 23 21:08:28 1998
--- src/docs/kb/wc202.txi Fri May 29 19:30:26 1998
***************
*** 391,393 ****
--- 391,397 ----
call fails, this variable gets assigned the value of the error code
returned by the failed DOS function.
@vindex _doserrno
+
+ @code{fflush} now conforms to ANSI C standard when called with a
+ @code{NULL} argument.
+ @findex fflush
*** src/libc/ansi/stdio/fwalk.t~0 Sun Aug 31 20:13:18 1997
--- src/libc/ansi/stdio/fwalk.txh Fri May 29 19:39:16 1998
***************
*** 10,16 ****
@subheading Description
For each open file in the system, the given @var{function} is called,
! passing the file pointer as it's only argument
@subheading Return Value
--- 10,16 ----
@subheading Description
For each open file in the system, the given @var{function} is called,
! passing the file pointer as its only argument.
@subheading Return Value
- Raw text -