]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix Build for Windows
authorW. Felix Handte <w@felixhandte.com>
Tue, 9 Mar 2021 06:24:11 +0000 (01:24 -0500)
committerW. Felix Handte <w@felixhandte.com>
Wed, 5 May 2021 17:10:34 +0000 (13:10 -0400)
programs/fileio.c
programs/platform.h

index 790c10b870af75a4e97319bf1a29ecaeb950574d..2b74feb855dece3cc210c72f676b3ec0b5534d87 100644 (file)
 
 #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");
index 3b8b505e18a02daafe7095dbc1aa0baeea73f05c..b858e3b484c21b196eacc129a913f6c2c6d55752 100644 (file)
@@ -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 <io.h> and <windows.h> */
 #    define snprintf sprintf_s       /* snprintf unsupported by Visual <= 2013 */