diff -ur bash-3.2.orig/config.h.in bash-3.2/config.h.in --- bash-3.2.orig/config.h.in 2006-09-12 23:00:54.000000000 +0300 +++ bash-3.2/config.h.in 2007-12-30 15:41:05.974625000 +0200 @@ -812,6 +812,13 @@ /* Define if you have the wcwidth function. */ #undef HAVE_WCWIDTH +/* Define if you have the fpurge function. */ +#undef HAVE_FPURGE + +/* Define if you have the __fpurge function. */ +#undef HAVE___FPURGE + + /* Presence of certain system include files. */ /* Define if you have the header file. */ diff -ur bash-3.2.orig/configure.in bash-3.2/configure.in --- bash-3.2.orig/configure.in 2006-09-26 18:05:45.000000000 +0300 +++ bash-3.2/configure.in 2007-12-30 15:14:52.206078000 +0200 @@ -721,6 +721,9 @@ AC_CHECK_DECLS([strcpy]) AC_CHECK_DECLS([strsignal]) +dnl checks for fpurge or __fpurge +AC_CHECK_FUNCS(fpurge __fpurge) + dnl Extra test to detect the horribly broken HP/UX 11.00 strtold(3) AC_CHECK_DECLS([strtold], [ AC_MSG_CHECKING([for broken strtold]) diff -ur bash-3.2.orig/redir.c bash-3.2/redir.c --- bash-3.2.orig/redir.c 2006-05-24 05:31:35.000000000 +0300 +++ bash-3.2/redir.c 2007-12-30 16:35:53.627539000 +0200 @@ -31,6 +31,18 @@ #include "filecntl.h" #include "posixstat.h" + +/* check for a way to clear the output buffer of a FILE *, for use + after dup on stdout/stderr */ +#undef FPURGE +#ifdef HAVE___FPURGE +#define FPURGE __fpurge +#endif +#ifdef HAVE_FPURGE +#define FPURGE fpurge +#endif + + #if defined (HAVE_UNISTD_H) # include #endif @@ -769,6 +781,19 @@ if ((fd != redirector) && (dup2 (fd, redirector) < 0)) return (errno); + +/* if possible, and the redirecting stdout/stderr, clear the stdio + output buffers, so output from shell builtins that previously + failed will not go to the redirected file */ +#ifdef FPURGE + if (redirector == 1) { + FPURGE(stdout); + } else if (redirector == 2) { + FPURGE(stderr); + } +#endif + + #if defined (BUFFERED_INPUT) /* Do not change the buffered stream for an implicit redirection of /dev/null to fd 0 for asynchronous commands without job @@ -851,6 +876,19 @@ return (r); } + +/* if possible, and the redirecting stdout/stderr, clear the stdio + output buffers, so output from shell builtins that previously + failed will not go to the redirected file */ +#ifdef FPURGE + if (redirector == 1) { + FPURGE(stdout); + } else if (redirector == 2) { + FPURGE(stderr); + } +#endif + + #if defined (BUFFERED_INPUT) duplicate_buffered_stream (fd, redirector); #endif @@ -890,6 +928,19 @@ if (dup2 (redir_fd, redirector) < 0) return (errno); + +/* if possible, and the redirecting stdout/stderr, clear the stdio + output buffers, so output from shell builtins that previously + failed will not go to the redirected file */ +#ifdef FPURGE + if (redirector == 1) { + FPURGE(stdout); + } else if (redirector == 2) { + FPURGE(stderr); + } +#endif + + #if defined (BUFFERED_INPUT) if (ri == r_duplicating_input || ri == r_move_input) duplicate_buffered_stream (redir_fd, redirector);