Skip to content

Commit

Permalink
Do not set feature test macro in public header
Browse files Browse the repository at this point in the history
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
  • Loading branch information
horgh committed Aug 4, 2023
1 parent 0c4d829 commit c3491e1
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 13 deletions.
5 changes: 4 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions bin/mmdblookup.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
Expand Down
12 changes: 0 additions & 12 deletions include/maxminddb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdarg.h>
#include <stdbool.h>
Expand Down
4 changes: 4 additions & 0 deletions src/data-pool.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifdef TEST_DATA_POOL
#define _POSIX_C_SOURCE 200809L
#endif

#include "data-pool.h"
#include "maxminddb.h"

Expand Down
1 change: 1 addition & 0 deletions t/bad_databases_t.c
Original file line number Diff line number Diff line change
@@ -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 <ftw.h>

Expand Down
2 changes: 2 additions & 0 deletions t/bad_pointers_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

void run_tests(int mode, const char *mode_desc) {
Expand Down
2 changes: 2 additions & 0 deletions t/basic_lookup_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

static void test_big_lookup(void);
Expand Down
2 changes: 2 additions & 0 deletions t/data-pool-t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "libtap/tap.h"
#include "maxminddb_test_helper.h"
#include <assert.h>
Expand Down
2 changes: 2 additions & 0 deletions t/data_entry_list_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

MMDB_entry_data_list_s *
Expand Down
2 changes: 2 additions & 0 deletions t/data_types_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

void test_all_data_types(MMDB_lookup_result_s *result,
Expand Down
2 changes: 2 additions & 0 deletions t/dump_t.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#define _XOPEN_SOURCE 700

#include "maxminddb_test_helper.h"

#ifdef HAVE_OPEN_MEMSTREAM
Expand Down
2 changes: 2 additions & 0 deletions t/get_value_pointer_bug_t.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions t/get_value_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

void test_array_0_result(int status,
Expand Down
2 changes: 2 additions & 0 deletions t/ipv4_start_cache_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

void test_one_ip(MMDB_s *mmdb,
Expand Down
2 changes: 2 additions & 0 deletions t/ipv6_lookup_in_ipv4_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

void run_tests(int mode, const char *mode_desc) {
Expand Down
2 changes: 2 additions & 0 deletions t/metadata_pointers_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

void run_tests(int mode, const char *mode_desc) {
Expand Down
2 changes: 2 additions & 0 deletions t/metadata_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

void test_metadata(MMDB_s *mmdb, const char *mode_desc) {
Expand Down
2 changes: 2 additions & 0 deletions t/no_map_get_value_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

void run_tests(int mode, const char *mode_desc) {
Expand Down
2 changes: 2 additions & 0 deletions t/read_node_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

void test_entry_data(MMDB_s *mmdb,
Expand Down
2 changes: 2 additions & 0 deletions t/threads_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"
#include <pthread.h>

Expand Down
2 changes: 2 additions & 0 deletions t/version_t.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L

#include "maxminddb_test_helper.h"

int main(void) {
Expand Down

0 comments on commit c3491e1

Please sign in to comment.