Skip to content

Commit d95c583

Browse files
authored
apps: ojph_sockets: Detect __GLIBC__ before using GNU-flavour strerror_r (#229)
According to manpage, glibc is the only libc implementation whose strerror_r() may return a char * pointer instead of int. Let's guard usage of the GNU-flavour prototype, instead of the standard XSI one. This should fix compilation on musl, *BSD, ..., etc. Signed-off-by: Yao Zi <[email protected]>
1 parent b7d12b0 commit d95c583

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/apps/others/ojph_sockets.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,16 @@ namespace ojph
165165
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
166166
buf, max_buf_size, NULL);
167167
buf[max_buf_size - 1] = 0;
168-
#elif (defined OJPH_OS_APPLE) || \
169-
((_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE)
168+
#elif (defined __GLIBC__) && \
169+
((defined _GNU_SOURCE) || (_POSIX_C_SOURCE < 200112L))
170+
v = strerror_r(errnum, (char*)buf, max_buf_size);
171+
#else
170172
// it is not clear if the returned value is in buf or in v
171173
int t = strerror_r(errnum, (char*)buf, max_buf_size);
172174
if (t != 0)
173175
OJPH_ERROR(0x00080002, "Error retrieving a text message for "
174176
"socket error number %d\n", errnum);
175177
buf[max_buf_size - 1] = 0;
176-
#else
177-
v = strerror_r(errnum, (char*)buf, max_buf_size);
178178
#endif
179179
std::string str;
180180
str = v;

0 commit comments

Comments
 (0)