Skip to content

Commit

Permalink
lib: escape usage of strerror_l() if it doesn't exist in libc
Browse files Browse the repository at this point in the history
uClibc doesn't implement strerror_l() and thus libnl starting from
3.2.29 couldn't be compiled with it any longer.

To work-around that problem we'll just do a check on strerror_l()
availability during configuration and if it's not there just fall back
to locale-less strerror().

See-also: 6c2d111

http://lists.infradead.org/pipermail/libnl/2017-March/002301.html

Signed-off-by: Alexey Brodkin <[email protected]>
Signed-off-by: Thomas Haller <[email protected]>
  • Loading branch information
abrodkin authored and thom311 committed Mar 12, 2017
1 parent bcdf874 commit e15966a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ fi

AC_CONFIG_SUBDIRS([doc])

AC_CHECK_FUNCS([strerror_l])

AC_CONFIG_FILES([
Makefile
libnl-3.0.pc
Expand Down
8 changes: 7 additions & 1 deletion lib/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include <netlink/utils.h>
#include <linux/socket.h>
#include <stdlib.h> /* exit() */
#ifdef HAVE_STRERROR_L
#include <locale.h>
#endif

/**
* Global variable indicating the desired level of debugging output.
Expand Down Expand Up @@ -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)
Expand All @@ -140,6 +143,9 @@ const char *nl_strerror_l(int err)
}

errno = errno_save;
#else
buf = strerror(err);
#endif
return buf;
}
/** @endcond */
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
Expand Down

0 comments on commit e15966a

Please sign in to comment.