Check for and work around buggy fflush(NULL).

Some really old platforms (eg SunOS4) segfault on fflush(NULL) so check
for and work around.  With klausz at haus-gisela.de.
This commit is contained in:
Darren Tucker 2018-03-05 19:28:08 +11:00
parent 71e48bc794
commit 58fd4c5c01
3 changed files with 30 additions and 0 deletions

View File

@ -2059,6 +2059,16 @@ AC_CHECK_FUNCS([realpath], [
)
])
AC_MSG_CHECKING([for working fflush(NULL)])
AC_RUN_IFELSE(
[AC_LANG_PROGRAM([[#include <stdio.h>]], [[fflush(NULL); exit(0);]])],
AC_MSG_RESULT([yes]),
[AC_MSG_RESULT([no])
AC_DEFINE([FFLUSH_NULL_BUG], [1],
[define if fflush(NULL) does not work])],
AC_MSG_WARN([cross compiling: assuming working])
)
dnl Checks for time functions
AC_CHECK_FUNCS([gettimeofday time])
dnl Checks for utmp functions

View File

@ -308,3 +308,19 @@ getsid(pid_t pid)
}
#endif
#ifdef FFLUSH_NULL_BUG
#undef fflush
int _ssh_compat_fflush(FILE *f)
{
int r1, r2, r3;
if (f == NULL) {
r2 = fflush(stdout);
r3 = fflush(stderr);
if (r1 == -1 || r2 == -1 || r3 == -1)
return -1;
return 0;
}
return fflush(f);
}
#endif

View File

@ -153,4 +153,8 @@ pid_t getsid(pid_t);
int flock(int, int);
#endif
#ifdef FFLUSH_NULL_BUG
# define fflush(x) (_ssh_compat_fflush(x))
#endif
#endif /* _BSD_MISC_H */