From bdeffc3fdc0219ba0081d8e08ddeb54808fe91a6 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 5 Feb 2015 07:04:22 -0800 Subject: [PATCH] Fix build on Android NDK where XSI-compliant version of strerror_r is used violating the docs at http://linux.die.net/man/3/strerror_r --- format.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/format.cc b/format.cc index 0c400aef..a4c9cee6 100644 --- a/format.cc +++ b/format.cc @@ -134,7 +134,13 @@ int safe_strerror( int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT(true) { assert(buffer != 0 && buffer_size != 0); int result = 0; -#ifdef _GNU_SOURCE +#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || __ANDROID__ + // XSI-compliant version of strerror_r. + result = strerror_r(error_code, buffer, buffer_size); + if (result != 0) + result = errno; +#elif _GNU_SOURCE + // GNU-specific version of strerror_r. char *message = strerror_r(error_code, buffer, buffer_size); // If the buffer is full then the message is probably truncated. if (message == buffer && strlen(buffer) == buffer_size - 1)