Use feature test macros properly in igs_resource_msg_from_err_unix.

Feature test macros should be used to inform the C library what
functions a program _expects_ to be available (and which should be made
available to it), not as checks for what functions are available to be
used. Therefore, it is necessary to set _POSIX_C_SOURCE to 200809L,
which indicates we wish to use functions defined in POSIX.2008, one of
which is `int strerror_r()`. This way, all libc (including glibc, as
long as _GNU_SOURCE is undefined) implementations will make the correct
version of the function available, and the fallback to the `char
*strerror_r()` version is no longer necessary.
This commit is contained in:
Érico Rolim 2020-09-25 04:07:44 -03:00 committed by manongjohn
parent 2e3c011ee3
commit 2c66a4ced9

View file

@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L /* int strerror_r() */
#undef _GNU_SOURCE
#include <cerrno>
#include <cstring> /* memset */
#include <vector>
@ -120,7 +122,7 @@ HP-UX(v11.23)では、strerror_r()をサポートしない。
::strerror()Thread SafeではなくMulti Threadでは正常動作しない
*/
errmsg += ::strerror(erno);
#elif defined(FREEBSD) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)
#elif !defined(__APPLE__)
/*
http://japanese-linux-man-pages.coding-school.com/man/X_strerror_r-3
POSIX.1.2002XSI準拠のバージョンのstrerror_r()
@ -152,21 +154,12 @@ http://japanese-linux-man-pages.coding-school.com/man/X_strerror_r-3
} else {
errmsg += "strerror_r() returns bad value";
}
#elif defined(__APPLE__)
#else
char buff[4096];
int ret = ::strerror_r(erno, buff, sizeof(buff));
if (!ret) {
errmsg += buff;
}
#else
/* linuxはここに来る?
http://japanese-linux-man-pages.coding-school.com/man/X_strerror_r-3
GNU仕様のバージョンのstrerror_r()
Thread Safeか??????
*/
char buff[4096];
const char *ret = ::strerror_r(erno, buff, sizeof(buff));
errmsg += ret;
#endif
}
errmsg += '\"';