From 45c4918ccf3719fc7cacb1a5001ae7d49afd0a70 Mon Sep 17 00:00:00 2001 From: "W. Felix Handte" Date: Tue, 9 Mar 2021 01:24:11 -0500 Subject: [PATCH] Fix Build for Windows --- programs/fileio.c | 14 +++++++++++++- programs/platform.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/programs/fileio.c b/programs/fileio.c index 790c10b87..2b74feb85 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -74,8 +74,12 @@ #define FNSPACE 30 +#if !defined(_WIN32) /* Default file permissions 0666 (modulated by umask) */ #define DEFAULT_FILE_PERMISSIONS (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) +#else +#define DEFAULT_FILE_PERMISSIONS (0) +#endif /*-************************************* * Macros @@ -692,7 +696,15 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs, FIO_removeFile(dstFileName); } - { const int fd = open(dstFileName, O_WRONLY|O_CREAT|O_TRUNC, mode); + { +#if defined(_WIN32) + /* Windows requires opening the file as a "binary" file to avoid + * mangling. This macro doesn't exist on unix. */ + const int openflags = O_WRONLY|O_CREAT|O_TRUNC|O_BINARY; +#else + const int openflags = O_WRONLY|O_CREAT|O_TRUNC; +#endif + const int fd = open(dstFileName, openflags, mode); FILE* f = NULL; if (fd != -1) { f = fdopen(fd, "wb"); diff --git a/programs/platform.h b/programs/platform.h index 3b8b505e1..b858e3b48 100644 --- a/programs/platform.h +++ b/programs/platform.h @@ -22,6 +22,7 @@ extern "C" { ****************************************/ #if defined(_MSC_VER) # define _CRT_SECURE_NO_WARNINGS /* Disable Visual Studio warning messages for fopen, strncpy, strerror */ +# define _CRT_NONSTDC_NO_WARNINGS /* Disable C4996 complaining about posix function names */ # if (_MSC_VER <= 1800) /* 1800 == Visual Studio 2013 */ # define _CRT_SECURE_NO_DEPRECATE /* VS2005 - must be declared before and */ # define snprintf sprintf_s /* snprintf unsupported by Visual <= 2013 */