diff --git a/appveyor.yml b/appveyor.yml
index c95be3b96..bfdbfe6c0 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -2,10 +2,10 @@ version: 1.0.{build}
environment:
matrix:
- COMPILER: "gcc"
- MAKE_PARAMS: "test"
+ MAKE_PARAMS: '"make test && make lib && make -C tests test-symbols fullbench-dll fullbench-lib"'
PLATFORM: "mingw64"
- COMPILER: "gcc"
- MAKE_PARAMS: "test"
+ MAKE_PARAMS: "make test"
PLATFORM: "mingw32"
- COMPILER: "visual"
CONFIGURATION: "Debug"
@@ -69,9 +69,8 @@ build_script:
ECHO *** &&
make -v &&
cc -v &&
- ECHO make %MAKE_PARAMS% &&
- make %MAKE_PARAMS% &&
- make -C tests test-symbols
+ ECHO %MAKE_PARAMS% &&
+ sh -c %MAKE_PARAMS%
)
- if [%COMPILER%]==[gcc] if [%PLATFORM%]==[mingw64] (
COPY programs\zstd.exe bin\zstd.exe &&
diff --git a/build/VS2010/fullbench-dll/fullbench-dll.vcxproj b/build/VS2010/fullbench-dll/fullbench-dll.vcxproj
index 3609f3ac0..e697318e0 100644
--- a/build/VS2010/fullbench-dll/fullbench-dll.vcxproj
+++ b/build/VS2010/fullbench-dll/fullbench-dll.vcxproj
@@ -99,6 +99,7 @@
true
$(SolutionDir)bin\$(Platform)_$(Configuration);%(AdditionalLibraryDirectories)
libzstd.lib;%(AdditionalDependencies)
+ false
@@ -138,6 +139,7 @@
true
$(SolutionDir)bin\$(Platform)_$(Configuration);%(AdditionalLibraryDirectories)
libzstd.lib;%(AdditionalDependencies)
+ false
diff --git a/lib/dll/example/fullbench-dll.vcxproj b/lib/dll/example/fullbench-dll.vcxproj
index 3faacbae1..44bbaf788 100644
--- a/lib/dll/example/fullbench-dll.vcxproj
+++ b/lib/dll/example/fullbench-dll.vcxproj
@@ -100,6 +100,7 @@
true
$(SolutionDir)..\dll;%(AdditionalLibraryDirectories)
libzstd.lib;%(AdditionalDependencies)
+ false
@@ -141,6 +142,7 @@
true
$(SolutionDir)..\dll;%(AdditionalLibraryDirectories)
libzstd.lib;%(AdditionalDependencies)
+ false
diff --git a/programs/bench.c b/programs/bench.c
index 6c2383a87..4089d6ba7 100644
--- a/programs/bench.c
+++ b/programs/bench.c
@@ -8,10 +8,20 @@
*/
+
+/* **************************************
+* Compiler Warnings
+****************************************/
+#ifdef _MSC_VER
+# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
+#endif
+
+
/* *************************************
* Includes
***************************************/
-#include "util.h" /* Compiler options, UTIL_GetFileSize, UTIL_sleep */
+#include "platform.h" /* Large Files support */
+#include "util.h" /* UTIL_getFileSize, UTIL_sleep */
#include /* malloc, free */
#include /* memset */
#include /* fprintf, fopen, ftello64 */
diff --git a/programs/datagen.c b/programs/datagen.c
index 1af5a38a5..d0116b972 100644
--- a/programs/datagen.c
+++ b/programs/datagen.c
@@ -9,35 +9,16 @@
-/* *************************************
-* Compiler Options
-***************************************/
-#if defined(_MSC_VER)
-# define _CRT_SECURE_NO_WARNINGS /* removes Visual warning on strerror() */
-# define _CRT_SECURE_NO_DEPRECATE /* removes VS2005 warning on strerror() */
-#endif
-
/*-************************************
* Dependencies
**************************************/
+#include "platform.h" /* SET_BINARY_MODE */
#include /* malloc, free */
#include /* FILE, fwrite, fprintf */
#include /* memcpy */
#include "mem.h" /* U32 */
-/*-************************************
-* OS-specific Includes
-**************************************/
-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
-# include /* _O_BINARY */
-# include /* _setmode, _isatty */
-# define SET_BINARY_MODE(file) {int unused = _setmode(_fileno(file), _O_BINARY); (void)unused; }
-#else
-# define SET_BINARY_MODE(file)
-#endif
-
-
/*-************************************
* Macros
**************************************/
diff --git a/programs/dibio.c b/programs/dibio.c
index fa4241b14..b95bab34e 100644
--- a/programs/dibio.c
+++ b/programs/dibio.c
@@ -9,10 +9,19 @@
+/* **************************************
+* Compiler Warnings
+****************************************/
+#ifdef _MSC_VER
+# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
+#endif
+
+
/*-*************************************
* Includes
***************************************/
-#include "util.h" /* Compiler options, UTIL_GetFileSize, UTIL_getTotalFileSize */
+#include "platform.h" /* Large Files support */
+#include "util.h" /* UTIL_getFileSize, UTIL_getTotalFileSize */
#include /* malloc, free */
#include /* memset */
#include /* fprintf, fopen, ftello64 */
diff --git a/programs/fileio.c b/programs/fileio.c
index 555b56141..a112cc049 100644
--- a/programs/fileio.c
+++ b/programs/fileio.c
@@ -11,7 +11,7 @@
* Compiler Options
***************************************/
#ifdef _MSC_VER /* Visual */
-# define _CRT_SECURE_NO_WARNINGS /* removes Visual warning on strerror() */
+# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
# pragma warning(disable : 4204) /* non-constant aggregate initializer */
#endif
#if defined(__MINGW32__) && !defined(_POSIX_SOURCE)
@@ -22,7 +22,8 @@
/*-*************************************
* Includes
***************************************/
-#include "util.h" /* Compiler options, UTIL_GetFileSize, _LARGEFILE64_SOURCE */
+#include "platform.h" /* Large Files support, SET_BINARY_MODE */
+#include "util.h" /* UTIL_getFileSize */
#include /* fprintf, fopen, fread, _fileno, stdin, stdout */
#include /* malloc, free */
#include /* strcmp, strlen */
@@ -41,19 +42,6 @@
#endif
-/*-*************************************
-* OS-specific Includes
-***************************************/
-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
-# include /* _O_BINARY */
-# include /* _setmode, _isatty */
-# define SET_BINARY_MODE(file) { if (_setmode(_fileno(file), _O_BINARY) == -1) perror("Cannot set _O_BINARY"); }
-#else
-# include /* isatty */
-# define SET_BINARY_MODE(file)
-#endif
-
-
/*-*************************************
* Constants
***************************************/
diff --git a/programs/platform.h b/programs/platform.h
new file mode 100644
index 000000000..f30528aa9
--- /dev/null
+++ b/programs/platform.h
@@ -0,0 +1,135 @@
+/**
+ * platform.h - compiler and OS detection
+ *
+ * Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+
+#ifndef PLATFORM_H_MODULE
+#define PLATFORM_H_MODULE
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
+
+
+/* **************************************
+* Compiler Options
+****************************************/
+#if defined(_MSC_VER)
+# define _CRT_SECURE_NO_WARNINGS /* Disable Visual Studio warning messages for fopen, strncpy, strerror */
+# define _CRT_SECURE_NO_DEPRECATE /* VS2005 - must be declared before and */
+# if (_MSC_VER <= 1800) /* (1800 = Visual Studio 2013) */
+# define snprintf sprintf_s /* snprintf unsupported by Visual <= 2013 */
+# endif
+#endif
+
+
+/* **************************************
+* Detect 64-bit OS
+* http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros
+****************************************/
+#if defined __ia64 || defined _M_IA64 /* Intel Itanium */ \
+ || defined __powerpc64__ || defined __ppc64__ || defined __PPC64__ /* POWER 64-bit */ \
+ || (defined __sparc && (defined __sparcv9 || defined __sparc_v9__ || defined __arch64__)) || defined __sparc64__ /* SPARC 64-bit */ \
+ || defined __x86_64__s || defined _M_X64 /* x86 64-bit */ \
+ || defined __arm64__ || defined __aarch64__ || defined __ARM64_ARCH_8__ /* ARM 64-bit */ \
+ || (defined __mips && (__mips == 64 || __mips == 4 || __mips == 3)) /* MIPS 64-bit */ \
+ || defined _LP64 || defined __LP64__ /* NetBSD, OpenBSD */ || defined __64BIT__ /* AIX */ || defined _ADDR64 /* Cray */ \
+ || (defined __SIZEOF_POINTER__ && __SIZEOF_POINTER__ == 8) /* gcc */
+# if !defined(__64BIT__)
+# define __64BIT__ 1
+# endif
+#endif
+
+
+/* *********************************************************
+* Turn on Large Files support (>4GB) for 32-bit Linux/Unix
+***********************************************************/
+#if !defined(__64BIT__) /* No point defining Large file for 64 bit */
+# if !defined(_FILE_OFFSET_BITS)
+# define _FILE_OFFSET_BITS 64 /* turn off_t into a 64-bit type for ftello, fseeko */
+# endif
+# if !defined(_LARGEFILE_SOURCE) /* obsolete macro, replaced with _FILE_OFFSET_BITS */
+# define _LARGEFILE_SOURCE 1 /* Large File Support extension (LFS) - fseeko, ftello */
+# endif
+# if defined(_AIX) || defined(__hpux)
+# define _LARGE_FILES /* Large file support on 32-bits AIX and HP-UX */
+# endif
+#endif
+
+
+/* ************************************************************
+* Detect POSIX version
+* PLATFORM_POSIX_VERSION = -1 for non-Unix e.g. Windows
+* PLATFORM_POSIX_VERSION = 0 for Unix-like non-POSIX
+* PLATFORM_POSIX_VERSION >= 1 is equal to found _POSIX_VERSION
+***************************************************************/
+#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) /* UNIX-like OS */ \
+ || defined(__midipix__) || defined(__VMS))
+# if (defined(__APPLE__) && defined(__MACH__)) || defined(__SVR4) || defined(_AIX) || defined(__hpux) /* POSIX.1–2001 (SUSv3) conformant */ \
+ || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) /* BSD distros */
+# define PLATFORM_POSIX_VERSION 200112L
+# else
+# if defined(__linux__) || defined(__linux)
+# define _POSIX_C_SOURCE 200112L /* use feature test macro */
+# endif
+# include /* declares _POSIX_VERSION */
+# if defined(_POSIX_VERSION) /* POSIX compliant */
+# define PLATFORM_POSIX_VERSION _POSIX_VERSION
+# else
+# define PLATFORM_POSIX_VERSION 0
+# endif
+# endif
+#endif
+#if !defined(PLATFORM_POSIX_VERSION)
+# define PLATFORM_POSIX_VERSION -1
+#endif
+
+
+/*-*********************************************
+* Detect if isatty() and fileno() are available
+************************************************/
+#if (defined(__linux__) && (PLATFORM_POSIX_VERSION >= 1)) || (PLATFORM_POSIX_VERSION >= 200112L) || defined(__DJGPP__)
+# include /* isatty */
+# define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
+#elif defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
+# include /* _isatty */
+# define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
+#else
+# define IS_CONSOLE(stdStream) 0
+#endif
+
+
+/******************************
+* OS-specific Includes
+******************************/
+#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32)
+# include /* _O_BINARY */
+# include /* _setmode, _fileno, _get_osfhandle */
+# if !defined(__DJGPP__)
+# include /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */
+# include /* FSCTL_SET_SPARSE */
+# define SET_BINARY_MODE(file) { int unused=_setmode(_fileno(file), _O_BINARY); (void)unused; }
+# define SET_SPARSE_FILE_MODE(file) { DWORD dw; DeviceIoControl((HANDLE) _get_osfhandle(_fileno(file)), FSCTL_SET_SPARSE, 0, 0, 0, 0, &dw, 0); }
+# else
+# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
+# define SET_SPARSE_FILE_MODE(file)
+# endif
+#else
+# define SET_BINARY_MODE(file)
+# define SET_SPARSE_FILE_MODE(file)
+#endif
+
+
+
+#if defined (__cplusplus)
+}
+#endif
+
+#endif /* PLATFORM_H_MODULE */
diff --git a/programs/util.h b/programs/util.h
index 0fa70577a..aaa4b7c1e 100644
--- a/programs/util.h
+++ b/programs/util.h
@@ -1,4 +1,6 @@
/**
+ * util.h - utility functions
+ *
* Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
* All rights reserved.
*
@@ -14,50 +16,57 @@
extern "C" {
#endif
-/* **************************************
-* Compiler Options
-****************************************/
-#if defined(__INTEL_COMPILER)
-# pragma warning(disable : 177) /* disable: message #177: function was declared but never referenced */
-#endif
-#if defined(_MSC_VER)
-# define _CRT_SECURE_NO_WARNINGS /* Disable some Visual warning messages for fopen, strncpy */
-# define _CRT_SECURE_NO_DEPRECATE /* VS2005 */
-# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
-#if _MSC_VER <= 1800 /* (1800 = Visual Studio 2013) */
-# define snprintf sprintf_s /* snprintf unsupported by Visual <= 2013 */
-#endif
-#endif
-
-
-/* Unix Large Files support (>4GB) */
-#if !defined(__LP64__) /* No point defining Large file for 64 bit */
-# define _FILE_OFFSET_BITS 64 /* turn off_t into a 64-bit type for ftello, fseeko */
-# if defined(__sun__) && !defined(_LARGEFILE_SOURCE) /* Sun Solaris 32-bits requires specific definitions */
-# define _LARGEFILE_SOURCE /* fseeko, ftello */
-# elif !defined(_LARGEFILE64_SOURCE)
-# define _LARGEFILE64_SOURCE /* off64_t, fseeko64, ftello64 */
-# endif
-#endif
/*-****************************************
* Dependencies
******************************************/
-#include /* features.h with _POSIX_C_SOURCE, malloc */
-#include /* fprintf */
-#include /* stat, utime */
-#include /* stat */
+#include "platform.h" /* PLATFORM_POSIX_VERSION */
+#include /* malloc */
+#include /* size_t, ptrdiff_t */
+#include /* fprintf */
+#include /* stat, utime */
+#include /* stat */
#if defined(_MSC_VER)
-# include /* utime */
-# include /* _chmod */
+# include /* utime */
+# include /* _chmod */
#else
# include /* chown, stat */
# include /* utime */
#endif
-#include /* time */
+#include /* time */
#include
-#include "mem.h" /* U32, U64 */
+#include "mem.h" /* U32, U64 */
+
+
+/*-****************************************
+* Sleep functions: Windows - Posix - others
+******************************************/
+#if defined(_WIN32)
+# include
+# define SET_HIGH_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)
+# define UTIL_sleep(s) Sleep(1000*s)
+# define UTIL_sleepMilli(milli) Sleep(milli)
+#elif PLATFORM_POSIX_VERSION >= 0 /* Unix-like operating system */
+# include
+# include /* setpriority */
+# include /* clock_t, nanosleep, clock, CLOCKS_PER_SEC */
+# if defined(PRIO_PROCESS)
+# define SET_HIGH_PRIORITY setpriority(PRIO_PROCESS, 0, -20)
+# else
+# define SET_HIGH_PRIORITY /* disabled */
+# endif
+# define UTIL_sleep(s) sleep(s)
+# if (defined(__linux__) && (PLATFORM_POSIX_VERSION >= 199309L)) || (PLATFORM_POSIX_VERSION >= 200112L) /* nanosleep requires POSIX.1-2001 */
+# define UTIL_sleepMilli(milli) { struct timespec t; t.tv_sec=0; t.tv_nsec=milli*1000000ULL; nanosleep(&t, NULL); }
+# else
+# define UTIL_sleepMilli(milli) /* disabled */
+# endif
+#else
+# define SET_HIGH_PRIORITY /* disabled */
+# define UTIL_sleep(s) /* disabled */
+# define UTIL_sleepMilli(milli) /* disabled */
+#endif
/* *************************************
@@ -69,6 +78,9 @@ extern "C" {
/*-****************************************
* Compiler specifics
******************************************/
+#if defined(__INTEL_COMPILER)
+# pragma warning(disable : 177) /* disable: message #177: function was declared but never referenced, useful with UTIL_STATIC */
+#endif
#if defined(__GNUC__)
# define UTIL_STATIC static __attribute__((unused))
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
@@ -80,36 +92,6 @@ extern "C" {
#endif
-/*-****************************************
-* Sleep functions: Windows - Posix - others
-******************************************/
-#if defined(_WIN32)
-# include
-# define SET_HIGH_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)
-# define UTIL_sleep(s) Sleep(1000*s)
-# define UTIL_sleepMilli(milli) Sleep(milli)
-#elif (defined(__unix__) || defined(__unix) || defined(__VMS) || defined(__midipix__) || (defined(__APPLE__) && defined(__MACH__)))
-# include
-# include /* setpriority */
-# include /* clock_t, nanosleep, clock, CLOCKS_PER_SEC */
-# if defined(PRIO_PROCESS)
-# define SET_HIGH_PRIORITY setpriority(PRIO_PROCESS, 0, -20)
-# else
-# define SET_HIGH_PRIORITY /* disabled */
-# endif
-# define UTIL_sleep(s) sleep(s)
-# if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 199309L))
-# define UTIL_sleepMilli(milli) { struct timespec t; t.tv_sec=0; t.tv_nsec=milli*1000000ULL; nanosleep(&t, NULL); }
-# else
-# define UTIL_sleepMilli(milli) /* disabled */
-# endif
-#else
-# define SET_HIGH_PRIORITY /* disabled */
-# define UTIL_sleep(s) /* disabled */
-# define UTIL_sleepMilli(milli) /* disabled */
-#endif
-
-
/*-****************************************
* Time functions
******************************************/
@@ -325,12 +307,10 @@ UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_
return nbFiles;
}
-#elif (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) || \
- (defined(__APPLE__) && defined(__MACH__)) || defined(__SVR4) || defined(_AIX) || defined(__hpux) || \
- defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
- (defined(__linux__) && defined(_POSIX_C_SOURCE)) /* opendir */
+#elif defined(__linux__) || (PLATFORM_POSIX_VERSION >= 200112L) /* opendir, readdir require POSIX.1-2001 */
# define UTIL_HAS_CREATEFILELIST
# include /* opendir, readdir */
+# include /* strerror, memcpy */
UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd)
{
@@ -392,7 +372,7 @@ UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_
UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char** bufEnd)
{
(void)bufStart; (void)bufEnd; (void)pos;
- fprintf(stderr, "Directory %s ignored (zstd compiled without _WIN32 or _POSIX_C_SOURCE)\n", dirName);
+ fprintf(stderr, "Directory %s ignored (compiled without _WIN32 or _POSIX_C_SOURCE)\n", dirName);
return 0;
}
diff --git a/programs/zstdcli.c b/programs/zstdcli.c
index c1eb7b732..978ffcfe0 100644
--- a/programs/zstdcli.c
+++ b/programs/zstdcli.c
@@ -23,7 +23,8 @@
/*-************************************
* Dependencies
**************************************/
-#include "util.h" /* Compiler options, UTIL_HAS_CREATEFILELIST */
+#include "platform.h" /* IS_CONSOLE, PLATFORM_POSIX_VERSION */
+#include "util.h" /* UTIL_HAS_CREATEFILELIST, UTIL_createFileList */
#include /* strcmp, strlen */
#include /* errno */
#include "fileio.h"
@@ -37,21 +38,6 @@
#include "zstd.h" /* ZSTD_VERSION_STRING */
-/*-************************************
-* OS-specific Includes
-**************************************/
-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
-# include /* _isatty */
-# define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
-#elif defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE) || (defined(__APPLE__) && defined(__MACH__)) || \
- defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) /* https://sourceforge.net/p/predef/wiki/OperatingSystems/ */
-# include /* isatty */
-# define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
-#else
-# define IS_CONSOLE(stdStream) 0
-#endif
-
-
/*-************************************
* Constants
**************************************/
@@ -499,6 +485,15 @@ int main(int argCount, const char* argv[])
/* Welcome message (if verbose) */
DISPLAYLEVEL(3, WELCOME_MESSAGE);
+#ifdef _POSIX_C_SOURCE
+ DISPLAYLEVEL(4, "_POSIX_C_SOURCE defined: %ldL\n", (long) _POSIX_C_SOURCE);
+#endif
+#ifdef _POSIX_VERSION
+ DISPLAYLEVEL(4, "_POSIX_VERSION defined: %ldL\n", (long) _POSIX_VERSION);
+#endif
+#ifdef PLATFORM_POSIX_VERSION
+ DISPLAYLEVEL(4, "PLATFORM_POSIX_VERSION defined: %ldL\n", (long) PLATFORM_POSIX_VERSION);
+#endif
#ifdef UTIL_HAS_CREATEFILELIST
if (recursive) { /* at this stage, filenameTable is a list of paths, which can contain both files and directories */