diff options
Diffstat (limited to 'libntp/msyslog.c')
-rw-r--r-- | libntp/msyslog.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libntp/msyslog.c b/libntp/msyslog.c index 9682d3002119..9a18c4d0d7b0 100644 --- a/libntp/msyslog.c +++ b/libntp/msyslog.c @@ -582,3 +582,41 @@ setup_logfile( msyslog(LOG_ERR, "Cannot reopen log file %s, %m", syslog_fname); } + +/* Helper for unit tests, where stdout + stderr are piped to the same + * stream. This works moderately reliable only if both streams are + * unbuffered or line buffered. Unfortunately stdout can be fully + * buffered on pipes or files... + */ +int +change_iobufs( + int how + ) +{ + int retv = 0; + +# ifdef HAVE_SETVBUF + + int mode; + + switch (how) { + case 0 : mode = _IONBF; break; /* no buffering */ + case 1 : mode = _IOLBF; break; /* line buffering */ + case 2 : mode = _IOFBF; break; /* full buffering */ + default: mode = _IOLBF; break; /* line buffering */ + } + + retv = 1; + if (setvbuf(stdout, NULL, mode, BUFSIZ) != 0) + retv = -1; + if (setvbuf(stderr, NULL, mode, BUFSIZ) != 0) + retv = -1; + +# else + + UNUSED_ARG(how); + +# endif + + return retv; +} |