Within glibc, it is always safe to call fflush (stdout), even if stdout has been previously closed. However, POSIX does not require this guarantee, and there are other platforms where attempting a flush in this situation causes a SIGSEGV: http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/18046/focus=18052 Since gnulib ports the error.c file to many other platforms, but wants to keep it in sync with glibc's version, it would be nice for glibc to apply this patch for portability. The attached patch makes the optimization of not calling fcntl on glibc, while still fixing the crash from the original gnulib report.
Created attachment 4060 [details] Avoid undefined behavior in error().
Created attachment 4061 [details] update patch to work on mingw
Created attachment 4407 [details] update patch to take into account possible freopen(stdout) calls