Hi Paul and Jim, It bothers me that in order to implement a basic functionality like the 'closeout' module, you need the __fpending module, which is not based on POSIX but rather a case-by-case hack for various platforms.
Here is a proposed patch to lift this dependency. Instead of using __fpending, the code in fwriteerror.c looks at the return code of fflush. The idea is that if the stream's output buffer is nonempty and fd=1 is an invalid file descriptor, fflush(stdout) must yield an EBADF error. 2006-09-29 Bruno Haible <[EMAIL PROTECTED]> * modules/close-stream (Depends-on): Add fwriterror. Remove fpending, stdbool. * lib/close-stream.c: Include fwriteerror.h. Don't include errno.h, stdbool.h, __fpending.h, unlocked-io.h. (close_stream): Call fwriteerror_no_ebadf. diff -c -3 -r1.2 close-stream *** modules/close-stream 21 Aug 2006 21:46:31 -0000 1.2 --- modules/close-stream 29 Sep 2006 14:05:54 -0000 *************** *** 7,14 **** m4/close-stream.m4 Depends-on: ! fpending ! stdbool configure.ac: gl_CLOSE_STREAM --- 7,13 ---- m4/close-stream.m4 Depends-on: ! fwriteerror configure.ac: gl_CLOSE_STREAM diff -c -3 -r1.2 close-stream.c *** lib/close-stream.c 13 Sep 2006 22:38:14 -0000 1.2 --- lib/close-stream.c 29 Sep 2006 14:05:54 -0000 *************** *** 21,34 **** #include "close-stream.h" ! #include <errno.h> ! #include <stdbool.h> ! ! #include "__fpending.h" ! ! #if USE_UNLOCKED_IO ! # include "unlocked-io.h" ! #endif /* Close STREAM. Return 0 if successful, EOF (setting errno) otherwise. A failure might set errno to 0 if the error number --- 21,27 ---- #include "close-stream.h" ! #include "fwriteerror.h" /* Close STREAM. Return 0 if successful, EOF (setting errno) otherwise. A failure might set errno to 0 if the error number *************** *** 53,62 **** int close_stream (FILE *stream) { - bool some_pending = (__fpending (stream) != 0); - bool prev_fail = (ferror (stream) != 0); - bool fclose_fail = (fclose (stream) != 0); - /* Return an error indication if there was a previous failure or if fclose failed, with one exception: ignore an fclose failure if there was no previous error, no data remains to be flushed, and --- 46,51 ---- *************** *** 64,76 **** is invoked like this `cp a b >&-' (i.e., with standard output closed) and doesn't generate any output (hence no previous error and nothing to be flushed). */ ! ! if (prev_fail || (fclose_fail && (some_pending || errno != EBADF))) ! { ! if (! fclose_fail) ! errno = 0; ! return EOF; ! } ! ! return 0; } --- 53,57 ---- is invoked like this `cp a b >&-' (i.e., with standard output closed) and doesn't generate any output (hence no previous error and nothing to be flushed). */ ! return (fwriteerror_no_ebadf (stream) < 0 ? EOF : 0); }