--- fileutils-4.0x/lib/closeout.c.orig Fri Oct 13 16:16:41 2000 +++ fileutils-4.0x/lib/closeout.c Fri Oct 13 16:22:55 2000 @@ -85,14 +85,22 @@ It's important to detect such failures and exit nonzero because many tools (most notably `make' and other build-management systems) depend - on being able to detect failure in other tools via their exit status. */ + on being able to detect failure in other tools via their exit status. + + NOTE HOWEVER! (Jan "Yenya" Kasprzak , Oct 13 2000) + We cannot raise an error condition if the caller tries to close + the already-closed file descriptor. If we did that, many utilities + (such as rm or ln) would stop working when called with closed + stdout. Thus we have to check the errno value after fclose, and if this + is EBADF (Bad file descriptor), we have to ignore that. */ void close_stdout_status (int status) { int e = ferror (stdout) ? 0 : -1; if (fclose (stdout) != 0) - e = errno; + if (errno != EBADF) + e = errno; if (0 <= e) {