#include "utils/ps_status.h"
#include "utils/timestamp.h"
-/*
- * We really want line-buffered mode for logfile output, but Windows does
- * not have it, and interprets _IOLBF as _IOFBF (bozos). So use _IONBF
- * instead on Windows.
- */
-#ifdef WIN32
-#define LBF_MODE _IONBF
-#else
-#define LBF_MODE _IOLBF
-#endif
-
/*
* We read() into a temp buffer twice as big as a chunk, so that any fragment
* left after processing can be moved down to the front and we'll still have
if (fd != -1)
{
syslogFile = fdopen(fd, "a");
- setvbuf(syslogFile, NULL, LBF_MODE, 0);
+ setvbuf(syslogFile, NULL, PG_IOLBF, 0);
}
#else /* WIN32 */
fd = atoi(*argv++);
if (fd > 0)
{
syslogFile = fdopen(fd, "a");
- setvbuf(syslogFile, NULL, LBF_MODE, 0);
+ setvbuf(syslogFile, NULL, PG_IOLBF, 0);
}
}
#endif /* WIN32 */
if (fh)
{
- setvbuf(fh, NULL, LBF_MODE, 0);
+ setvbuf(fh, NULL, PG_IOLBF, 0);
#ifdef WIN32
/* use CRLF line endings on Windows */
* unexpected output ordering when, eg, output is redirected to a file.
* POSIX says we must do this before any other usage of these files.
*/
- setvbuf(stdout, NULL, _IOLBF, 0);
+ setvbuf(stdout, NULL, PG_IOLBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
progname = get_progname(argv[0]);
#define closesocket close
#endif /* WIN32 */
+/*
+ * On Windows, setvbuf() does not support _IOLBF mode, and interprets that
+ * as _IOFBF. To add insult to injury, setvbuf(file, NULL, _IOFBF, 0)
+ * crashes outright if "parameter validation" is enabled. Therefore, in
+ * places where we'd like to select line-buffered mode, we fall back to
+ * unbuffered mode instead on Windows. Always use PG_IOLBF not _IOLBF
+ * directly in order to implement this behavior.
+ */
+#ifndef WIN32
+#define PG_IOLBF _IOLBF
+#else
+#define PG_IOLBF _IONBF
+#endif
+
/*
* Default "extern" declarations or macro substitutes for library routines.
* When necessary, these routines are provided by files in src/port/.