]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix the c99/cmake build under Cygwin/MSYS2
authorChristoph Reiter <reiter.christoph@gmail.com>
Sat, 11 Jan 2020 00:04:14 +0000 (01:04 +0100)
committerChristoph Reiter <reiter.christoph@gmail.com>
Sat, 11 Jan 2020 00:39:10 +0000 (01:39 +0100)
When building zst under cygwin or msys2 with std=c99 the build would fail because
of an undefined fileno()/_fileno(), which is used by the IS_CONSOLE() macro.

When building with -std=c99 (gcc otherwise defaults to gnu, which implies POSIX),
which is the default of the cmake build, then including unistd.h wont define
_POSIX_VERSION and all other headers also wont expose POSIX API.

To fix this make sure to define _POSIX_C_SOURCE with the version we want before including
unistd.h and so that _POSIX_VERSION is set to the version provided by the system.

Since Cygwin/MSYS2 just follow POSIX we can also remove their special cases for
defining IS_CONSOLE().

And, for completeness, also explicitly include stdio.h which is what actually declares fileno().

Tested with the normal make file and cmake under MSYS2 and Cygwin.

programs/platform.h

index 64ecd21fcdc4049cde5270eea0ed57823975a854..31820631eeabc35c5449f8aacf0617ad5f9a2ae4 100644 (file)
@@ -90,7 +90,7 @@ extern "C" {
      && ( defined(__unix__) || defined(__unix) \
        || defined(__midipix__) || defined(__VMS) || defined(__HAIKU__) )
 
-#    if defined(__linux__) || defined(__linux)
+#    if defined(__linux__) || defined(__linux) || defined(__CYGWIN__)
 #      ifndef _POSIX_C_SOURCE
 #        define _POSIX_C_SOURCE 200809L  /* feature test macro : https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html */
 #      endif
@@ -123,11 +123,11 @@ extern "C" {
 ************************************************/
 #if (defined(__linux__) && (PLATFORM_POSIX_VERSION > 1)) \
  || (PLATFORM_POSIX_VERSION >= 200112L) \
- || defined(__DJGPP__) \
- || defined(__MSYS__)
+ || defined(__DJGPP__)
 #  include <unistd.h>   /* isatty */
+#  include <stdio.h>    /* fileno */
 #  define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
-#elif defined(MSDOS) || defined(OS2) || defined(__CYGWIN__)
+#elif defined(MSDOS) || defined(OS2)
 #  include <io.h>       /* _isatty */
 #  define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
 #elif defined(WIN32) || defined(_WIN32)