Skip to content

Commit f9e5e0e

Browse files
authored
MONGOCRYPT-773 check if _GNU_SOURCE is defined before defining (#977)
Avoid a possible redefinition warning when building with `_GNU_SOURCE` defined by build system.
1 parent 3f8668d commit f9e5e0e

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

kms-message/test/test_kms_request.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616

1717
/* Needed for strptime */
18+
#if !defined(_GNU_SOURCE)
1819
#define _GNU_SOURCE
20+
#endif
1921

2022
#include "kms_message/kms_message.h"
2123
#include "kms_message_private.h"

src/mongocrypt-util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
#if defined(__has_include) && !(defined(_GNU_SOURCE) || defined(_DARWIN_C_SOURCE))
1919
#if __has_include(<features.h>)
2020
// We're using a glibc-compatible library
21+
#if !defined(_GNU_SOURCE)
2122
#define _GNU_SOURCE
23+
#endif
2224
#elif __has_include(<Availability.h>)
2325
// We're on Apple/Darwin
2426
#define _DARWIN_C_SOURCE
2527
#endif
2628
#else // No __has_include
27-
#if __GNUC__ < 5
29+
#if __GNUC__ < 5 && !defined(_GNU_SOURCE)
2830
// Best guess on older GCC is that we are using glibc
2931
#define _GNU_SOURCE
3032
#endif

src/os_posix/os_dll.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
#if defined(__has_include) && !(defined(_GNU_SOURCE) || defined(_DARWIN_C_SOURCE))
33
#if __has_include(<features.h>)
44
// We're using a glibc-compatible library
5+
#if !defined(_GNU_SOURCE)
56
#define _GNU_SOURCE
7+
#endif
68
#elif __has_include(<Availability.h>)
79
// We're on Apple/Darwin
810
#define _DARWIN_C_SOURCE
911
#endif
1012
#else // No __has_include
11-
#if __GNUC__ < 5
13+
#if __GNUC__ < 5 && !defined(_GNU_SOURCE)
1214
// Best guess on older GCC is that we are using glibc
1315
#define _GNU_SOURCE
1416
#endif

0 commit comments

Comments
 (0)