From e2c8463af7188287a7f3389c8f867f47a96b5d2a 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 | 4 ++++ include/maxminddb.h | 12 ------------ src/data-pool.c | 4 ++++ src/maxminddb.c | 4 ++++ t/bad_databases_t.c | 3 +++ t/bad_pointers_t.c | 4 ++++ t/basic_lookup_t.c | 4 ++++ t/data-pool-t.c | 4 ++++ t/data_entry_list_t.c | 4 ++++ t/data_types_t.c | 4 ++++ t/dump_t.c | 4 ++++ t/get_value_pointer_bug_t.c | 4 ++++ t/get_value_t.c | 4 ++++ t/ipv4_start_cache_t.c | 4 ++++ t/ipv6_lookup_in_ipv4_t.c | 4 ++++ t/metadata_pointers_t.c | 4 ++++ t/metadata_t.c | 4 ++++ t/no_map_get_value_t.c | 4 ++++ t/read_node_t.c | 4 ++++ t/threads_t.c | 4 ++++ t/version_t.c | 4 ++++ 22 files changed, 83 insertions(+), 13 deletions(-) diff --git a/Changes.md b/Changes.md index 384e7b0e..d0cd76ca 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 test 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..3652cd51 100644 --- a/bin/mmdblookup.c +++ b/bin/mmdblookup.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..7d47ddff 100644 --- a/src/data-pool.c +++ b/src/data-pool.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #include "data-pool.h" #include "maxminddb.h" diff --git a/src/maxminddb.c b/src/maxminddb.c index 7da1d340..c965c2a3 100644 --- a/src/maxminddb.c +++ b/src/maxminddb.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #if HAVE_CONFIG_H #include #endif diff --git a/t/bad_databases_t.c b/t/bad_databases_t.c index 54003d72..50967c63 100644 --- a/t/bad_databases_t.c +++ b/t/bad_databases_t.c @@ -1,5 +1,8 @@ // This test currently does not work on Windows as nftw is // not available. +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif #define _XOPEN_SOURCE 500 #include diff --git a/t/bad_pointers_t.c b/t/bad_pointers_t.c index 6247539a..1c8ed8f3 100644 --- a/t/bad_pointers_t.c +++ b/t/bad_pointers_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..20c73932 100644 --- a/t/basic_lookup_t.c +++ b/t/basic_lookup_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..aa11c077 100644 --- a/t/data-pool-t.c +++ b/t/data-pool-t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..d473f02e 100644 --- a/t/data_entry_list_t.c +++ b/t/data_entry_list_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..bc83feea 100644 --- a/t/data_types_t.c +++ b/t/data_types_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..fcb45a60 100644 --- a/t/dump_t.c +++ b/t/dump_t.c @@ -1,4 +1,8 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif #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..89fe133e 100644 --- a/t/get_value_pointer_bug_t.c +++ b/t/get_value_pointer_bug_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..99257c14 100644 --- a/t/get_value_t.c +++ b/t/get_value_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..191e7209 100644 --- a/t/ipv4_start_cache_t.c +++ b/t/ipv4_start_cache_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..9b994046 100644 --- a/t/ipv6_lookup_in_ipv4_t.c +++ b/t/ipv6_lookup_in_ipv4_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..f0f9ac37 100644 --- a/t/metadata_pointers_t.c +++ b/t/metadata_pointers_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..c4b27076 100644 --- a/t/metadata_t.c +++ b/t/metadata_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..40d04389 100644 --- a/t/no_map_get_value_t.c +++ b/t/no_map_get_value_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..d66b39a4 100644 --- a/t/read_node_t.c +++ b/t/read_node_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #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..198018a9 100644 --- a/t/threads_t.c +++ b/t/threads_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #include "maxminddb_test_helper.h" #include diff --git a/t/version_t.c b/t/version_t.c index 401d2a5e..8a31bfa5 100644 --- a/t/version_t.c +++ b/t/version_t.c @@ -1,3 +1,7 @@ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + #include "maxminddb_test_helper.h" int main(void) {