]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Bump _POSIX_C_SOURCE to 200809 for strdup()
authorIlya Leoshkevich <iii@linux.ibm.com>
Tue, 28 Jun 2022 08:51:39 +0000 (10:51 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 30 Jun 2022 10:23:11 +0000 (12:23 +0200)
Google Test uses strdup(), which makes building tests fail on a fresh
MSYS2 setup:

In file included from zlib-ng/_deps/googletest-src/googletest/include/gtest/internal/gtest-internal.h:40,
                 from zlib-ng/_deps/googletest-src/googletest/include/gtest/gtest.h:62,
                 from zlib-ng/test/test_compress.cc:17:
zlib-ng/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h: In function ‘char* testing::internal::posix::StrDup(const char*)’:
zlib-ng/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h:2046:47: error: ‘strdup’ was not declared in this scope; did you mean ‘StrDup’?
 2046 | inline char* StrDup(const char* src) { return strdup(src); }
      |                                               ^~~~~~
      |                                               StrDup

Bump _POSIX_C_SOURCE to enable this function. An alternative solution
would be to define _POSIX_C_SOURCE in test/CMakeLists.txt, but having a
bigger value for zlib-ng itself should not hurt.

Include zbuild.h earlier in minideflate.c in order to make the new
setting take effect for this file.

test/minideflate.c
zbuild.h

index 148a277692a8addb0fc3457088a2bb2ffb196278..987e6121baaeb734814270f495b83f3eb4748049 100644 (file)
@@ -3,10 +3,11 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
+#include "zbuild.h"
+
 #include <stdio.h>
 #include <assert.h>
 
-#include "zbuild.h"
 #include "zutil.h"
 
 #if defined(_WIN32) || defined(__CYGWIN__)
index 82374b1f14e6f1715045e76ef85281a1815cf117..d82c1c388efa80d47e22410be429fe1197592132 100644 (file)
--- a/zbuild.h
+++ b/zbuild.h
@@ -3,7 +3,7 @@
 
 #define _POSIX_SOURCE 1  /* fileno */
 #ifndef _POSIX_C_SOURCE
-#  define _POSIX_C_SOURCE 200112L /* snprintf, posix_memalign */
+#  define _POSIX_C_SOURCE 200809L /* snprintf, posix_memalign, strdup */
 #endif
 
 #include <stddef.h>