From c3491e1aaa12340dba36b3c4fbc4433fa4fc3eee Mon Sep 17 00:00:00 2001 From: William Storey Date: Fri, 4 Aug 2023 14:31:29 -0700 Subject: [PATCH] Do not set feature test macro in public header We believe that this should be set by applications rather than by the library. The spec suggests that having it in this spot is not correct as it should be set prior to any header being included. See https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02. Fixes #318 --- Changes.md | 5 ++++- bin/mmdblookup.c | 2 ++ include/maxminddb.h | 12 ------------ src/data-pool.c | 4 ++++ t/bad_databases_t.c | 1 + t/bad_pointers_t.c | 2 ++ t/basic_lookup_t.c | 2 ++ t/data-pool-t.c | 2 ++ t/data_entry_list_t.c | 2 ++ t/data_types_t.c | 2 ++ t/dump_t.c | 2 ++ t/get_value_pointer_bug_t.c | 2 ++ t/get_value_t.c | 2 ++ t/ipv4_start_cache_t.c | 2 ++ t/ipv6_lookup_in_ipv4_t.c | 2 ++ t/metadata_pointers_t.c | 2 ++ t/metadata_t.c | 2 ++ t/no_map_get_value_t.c | 2 ++ t/read_node_t.c | 2 ++ t/threads_t.c | 2 ++ t/version_t.c | 2 ++ 21 files changed, 43 insertions(+), 13 deletions(-) diff --git a/Changes.md b/Changes.md index 384e7b0e..50483fb6 100644 --- a/Changes.md +++ b/Changes.md @@ -1,7 +1,10 @@ -## 1.7.2 +## 1.8.0 * `PACKAGE_VERSION` is now a private compile definition when building with CMake. Pull request by bsergean. GitHub #308. +* The feature macro `_POSIX_C_SOURCE` is no longer set by `maxminddb.h`. As + discussed in GitHub #318, this should be set by applications rather than + by libraries. ## 1.7.1 - 2022-09-30 diff --git a/bin/mmdblookup.c b/bin/mmdblookup.c index 1989c57b..25e6ab8e 100644 --- a/bin/mmdblookup.c +++ b/bin/mmdblookup.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #ifdef HAVE_CONFIG_H #include #endif diff --git a/include/maxminddb.h b/include/maxminddb.h index 028aa214..980abf99 100644 --- a/include/maxminddb.h +++ b/include/maxminddb.h @@ -5,18 +5,6 @@ extern "C" { #ifndef MAXMINDDB_H #define MAXMINDDB_H -/* Request POSIX.1-2008. However, we want to remain compatible with - * POSIX.1-2001 (since we have been historically and see no reason to drop - * compatibility). By requesting POSIX.1-2008, we can conditionally use - * features provided by that standard if the implementation provides it. We can - * check for what the implementation provides by checking the _POSIX_VERSION - * macro after including unistd.h. If a feature is in POSIX.1-2008 but not - * POSIX.1-2001, check that macro before using the feature (or check for the - * feature directly if possible). */ -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200809L -#endif - #include "maxminddb_config.h" #include #include diff --git a/src/data-pool.c b/src/data-pool.c index 7b3c2a59..a920d889 100644 --- a/src/data-pool.c +++ b/src/data-pool.c @@ -1,3 +1,7 @@ +#ifdef TEST_DATA_POOL +#define _POSIX_C_SOURCE 200809L +#endif + #include "data-pool.h" #include "maxminddb.h" diff --git a/t/bad_databases_t.c b/t/bad_databases_t.c index 54003d72..7f076775 100644 --- a/t/bad_databases_t.c +++ b/t/bad_databases_t.c @@ -1,5 +1,6 @@ // This test currently does not work on Windows as nftw is // not available. +#define _POSIX_C_SOURCE 200809L #define _XOPEN_SOURCE 500 #include diff --git a/t/bad_pointers_t.c b/t/bad_pointers_t.c index 6247539a..44343c4e 100644 --- a/t/bad_pointers_t.c +++ b/t/bad_pointers_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" void run_tests(int mode, const char *mode_desc) { diff --git a/t/basic_lookup_t.c b/t/basic_lookup_t.c index adb4349e..e51fb800 100644 --- a/t/basic_lookup_t.c +++ b/t/basic_lookup_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" static void test_big_lookup(void); diff --git a/t/data-pool-t.c b/t/data-pool-t.c index ff8907c0..ff4f1fa7 100644 --- a/t/data-pool-t.c +++ b/t/data-pool-t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "libtap/tap.h" #include "maxminddb_test_helper.h" #include diff --git a/t/data_entry_list_t.c b/t/data_entry_list_t.c index 76eb2266..5b66b25e 100644 --- a/t/data_entry_list_t.c +++ b/t/data_entry_list_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" MMDB_entry_data_list_s * diff --git a/t/data_types_t.c b/t/data_types_t.c index 9a97c5c5..eceae936 100644 --- a/t/data_types_t.c +++ b/t/data_types_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" void test_all_data_types(MMDB_lookup_result_s *result, diff --git a/t/dump_t.c b/t/dump_t.c index dae32ef8..3bfa0c9d 100644 --- a/t/dump_t.c +++ b/t/dump_t.c @@ -1,4 +1,6 @@ +#define _POSIX_C_SOURCE 200809L #define _XOPEN_SOURCE 700 + #include "maxminddb_test_helper.h" #ifdef HAVE_OPEN_MEMSTREAM diff --git a/t/get_value_pointer_bug_t.c b/t/get_value_pointer_bug_t.c index 2d1d5290..00faa589 100644 --- a/t/get_value_pointer_bug_t.c +++ b/t/get_value_pointer_bug_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" /* This test exercises a bug found in MMDB_get_value for certain types of diff --git a/t/get_value_t.c b/t/get_value_t.c index 06dcf3b5..e4e49e7a 100644 --- a/t/get_value_t.c +++ b/t/get_value_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" void test_array_0_result(int status, diff --git a/t/ipv4_start_cache_t.c b/t/ipv4_start_cache_t.c index cfd9f57f..899675f7 100644 --- a/t/ipv4_start_cache_t.c +++ b/t/ipv4_start_cache_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" void test_one_ip(MMDB_s *mmdb, diff --git a/t/ipv6_lookup_in_ipv4_t.c b/t/ipv6_lookup_in_ipv4_t.c index 0d80f1ea..c3a949d1 100644 --- a/t/ipv6_lookup_in_ipv4_t.c +++ b/t/ipv6_lookup_in_ipv4_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" void run_tests(int mode, const char *mode_desc) { diff --git a/t/metadata_pointers_t.c b/t/metadata_pointers_t.c index f3f9ff5c..d1380522 100644 --- a/t/metadata_pointers_t.c +++ b/t/metadata_pointers_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" void run_tests(int mode, const char *mode_desc) { diff --git a/t/metadata_t.c b/t/metadata_t.c index 8acf7c73..cfd746d3 100644 --- a/t/metadata_t.c +++ b/t/metadata_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" void test_metadata(MMDB_s *mmdb, const char *mode_desc) { diff --git a/t/no_map_get_value_t.c b/t/no_map_get_value_t.c index 8f5b79ea..9f4434c5 100644 --- a/t/no_map_get_value_t.c +++ b/t/no_map_get_value_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" void run_tests(int mode, const char *mode_desc) { diff --git a/t/read_node_t.c b/t/read_node_t.c index 8941ade6..61f3c449 100644 --- a/t/read_node_t.c +++ b/t/read_node_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" void test_entry_data(MMDB_s *mmdb, diff --git a/t/threads_t.c b/t/threads_t.c index 7adf7a30..28fb89ea 100644 --- a/t/threads_t.c +++ b/t/threads_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" #include diff --git a/t/version_t.c b/t/version_t.c index 401d2a5e..39a2cab3 100644 --- a/t/version_t.c +++ b/t/version_t.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "maxminddb_test_helper.h" int main(void) {