Bruno Haible wrote: > Thanks for explaining. I think an alternative for bash would be to > temporarily set the file descriptor to point to /dev/null and do a > second fflush. Like this (error checking omitted): > > FILE *fp = ... /* stdout or stderr */; > if (fflush (fp) < 0) > { > #if GNULIB_PROVIDES_FPURGE > fpurge (fp); > #else > int fd = fileno (fp); > int saved_fd = dup (fd); > int sink_fd = open ("/dev/null", O_WRONLY); > dup2 (sink_fd, fd); > fflush (fp); > close (sink_fd); > dup2 (saved_fd, fd); > close (saved_fd); > #endif > }
That seems like a lot of trouble (and there's more that you have here, since bash also has to worry about the close-on-exec state of the file descriptor). A simple solution is to turn the #error into a #warning, and add a return 0 to make the function into a no-op, on the assumption that those versions of libc for which this is a problem (later versions of glibc) already provide fpurge. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/