diff --git a/configure.ac b/configure.ac index 68b285e5b..2739b997e 100644 --- a/configure.ac +++ b/configure.ac @@ -121,6 +121,8 @@ fi AC_CONFIG_SUBDIRS([doc]) +AC_CHECK_FUNCS([strerror_l]) + AC_CONFIG_FILES([ Makefile libnl-3.0.pc diff --git a/lib/utils.c b/lib/utils.c index fb350d13f..06273c5b2 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -30,7 +30,9 @@ #include #include #include /* exit() */ +#ifdef HAVE_STRERROR_L #include +#endif /** * Global variable indicating the desired level of debugging output. @@ -123,9 +125,10 @@ int __nl_read_num_str_file(const char *path, int (*cb)(long, const char *)) const char *nl_strerror_l(int err) { + const char *buf; +#ifdef HAVE_STRERROR_L int errno_save = errno; locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0); - const char *buf; if (loc == (locale_t)0) { if (errno == ENOENT) @@ -140,6 +143,9 @@ const char *nl_strerror_l(int err) } errno = errno_save; +#else + buf = strerror(err); +#endif return buf; } /** @endcond */ diff --git a/src/lib/utils.c b/src/lib/utils.c index 5878f279c..feb1d4ef4 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -81,6 +81,7 @@ void nl_cli_fatal(int err, const char *fmt, ...) fprintf(stderr, "\n"); } else { char *buf; +#ifdef HAVE_STRERROR_L locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0); if (loc == (locale_t)0) { if (errno == ENOENT) @@ -91,9 +92,14 @@ void nl_cli_fatal(int err, const char *fmt, ...) } if (loc != (locale_t)0) buf = strerror_l(err, loc); +#else + buf = strerror(err); +#endif fprintf(stderr, "%s\n", buf); +#ifdef HAVE_STRERROR_L if (loc != (locale_t)0) freelocale(loc); +#endif } exit(abs(err));