Skip to content

Commit 6378e8b

Browse files
committed
Revert "CDRIVER-4679 Prefer XSI-compliant strerror_r when available (mongodb#1350)"
This reverts commit ac436db.
1 parent f974c49 commit 6378e8b

File tree

4 files changed

+7
-50
lines changed

4 files changed

+7
-50
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ endif ()
394394
# Enable POSIX features up to POSIX.1-2008 plus the XSI extension and BSD-derived definitions.
395395
# Both _BSD_SOURCE and _DEFAULT_SOURCE are defined for backwards-compatibility with glibc 2.19 and earlier.
396396
# _BSD_SOURCE and _DEFAULT_SOURCE are required by `getpagesize`, `h_errno`, etc.
397-
# _XOPEN_SOURCE=700 is required by `strnlen`, `strerror_r`, etc.
397+
# _XOPEN_SOURCE=700 is required by `strnlen`, etc.
398398
add_definitions (-D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE)
399399
list (APPEND CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE)
400400

src/libbson/CMakeLists.txt

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ include (MongoC-Warnings)
1414

1515
set (BSON_OUTPUT_BASENAME "bson" CACHE STRING "Output bson library base name")
1616

17-
include (CheckCSourceCompiles)
1817
include (CheckFunctionExists)
1918
include (CheckIncludeFile)
20-
include (CheckIncludeFiles)
2119
include (CheckStructHasMember)
2220
include (CheckSymbolExists)
23-
include (InstallRequiredSystemLibraries)
2421
include (TestBigEndian)
22+
include (InstallRequiredSystemLibraries)
2523

2624
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/build/cmake)
2725

@@ -85,6 +83,8 @@ else ()
8583
set (BSON_OS 1)
8684
endif ()
8785

86+
include (CheckIncludeFiles)
87+
8888
CHECK_INCLUDE_FILE (strings.h BSON_HAVE_STRINGS_H)
8989
if (NOT BSON_HAVE_STRINGS_H)
9090
set (BSON_HAVE_STRINGS_H 0)
@@ -119,38 +119,6 @@ else ()
119119
set (BSON_BYTE_ORDER 1234)
120120
endif ()
121121

122-
# 1. Normally, `defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600` should be enough
123-
# to detect if an XSI-compliant `strerror_r` is available.
124-
# 2. However, GNU provides an incompatible `strerror_r` as an extension,
125-
# requiring an additional test for `!defined(_GNU_SOURCE)`.
126-
# 3. However, musl does not support the GNU extension even when `_GNU_SOURCE` is
127-
# defined, preventing `!defined(_GNU_SOURCE)` from being a portable
128-
# XSI-compliance test.
129-
# 4. However, musl does not provide a feature test macro to detect compilation
130-
# with musl, and workarounds that use internal glibc feature test macros such
131-
# as `defined(__USE_GNU)` are explicitly forbidden by glibc documentation.
132-
# 5. Therefore, give up on using feature test macros: use `CheckCSourceCompiles`
133-
# to test if the current `strerror_r` is XSI-compliant if present.
134-
if (NOT WIN32)
135-
CHECK_C_SOURCE_COMPILES(
136-
[[
137-
#include <string.h>
138-
int test(int errnum, char *buf, size_t buflen) {
139-
return strerror_r (errnum, buf, buflen);
140-
}
141-
int main(void) {}
142-
]]
143-
BSON_HAVE_XSI_STRERROR_R
144-
FAIL_REGEX "int-conversion"
145-
)
146-
endif ()
147-
148-
if (BSON_HAVE_XSI_STRERROR_R)
149-
set(BSON_HAVE_XSI_STRERROR_R 1)
150-
else()
151-
set(BSON_HAVE_XSI_STRERROR_R 0)
152-
endif ()
153-
154122
configure_file (
155123
"${PROJECT_SOURCE_DIR}/src/bson/bson-config.h.in"
156124
"${PROJECT_BINARY_DIR}/src/bson/bson-config.h"

src/libbson/src/bson/bson-config.h.in

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,4 @@
122122
# undef BSON_HAVE_STRLCPY
123123
#endif
124124

125-
126-
/*
127-
* Define to 1 if you have an XSI-compliant strerror_r on your platform.
128-
*/
129-
#define BSON_HAVE_XSI_STRERROR_R @BSON_HAVE_XSI_STRERROR_R@
130-
#if BSON_HAVE_XSI_STRERROR_R != 1
131-
# undef BSON_HAVE_XSI_STRERROR_R
132-
#endif
133-
134125
#endif /* BSON_CONFIG_H */

src/libbson/src/bson/bson-error.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,12 @@ bson_strerror_r (int err_code, /* IN */
109109
if (strerror_s (buf, buflen, err_code) != 0) {
110110
ret = buf;
111111
}
112-
#elif defined(BSON_HAVE_XSI_STRERROR_R)
112+
#elif defined(__GNUC__) && defined(_GNU_SOURCE)
113+
ret = strerror_r (err_code, buf, buflen);
114+
#else /* XSI strerror_r */
113115
if (strerror_r (err_code, buf, buflen) == 0) {
114116
ret = buf;
115117
}
116-
#elif defined(_GNU_SOURCE)
117-
ret = strerror_r (err_code, buf, buflen);
118-
#else
119-
#error "Unable to find a supported strerror_r candidate"
120118
#endif
121119

122120
if (!ret) {

0 commit comments

Comments
 (0)