diff --git a/include/Makefile.am b/include/Makefile.am index 804e984ed..f8b977ac4 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -166,6 +166,7 @@ noinst_HEADERS = \ netlink-private/socket.h \ netlink-private/tc.h \ netlink-private/types.h \ + netlink-private/utils.h \ netlink-private/cache-api.h \ netlink-private/object-api.h \ netlink-private/route/link/api.h \ diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h new file mode 100644 index 000000000..77aadb3b4 --- /dev/null +++ b/include/netlink-private/utils.h @@ -0,0 +1,17 @@ +/* + * netlink-private/utils.h Local Utility Functions + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2012 Thomas Graf + */ + +#ifndef NETLINK_UTILS_PRIV_H_ +#define NETLINK_UTILS_PRIV_H_ + +extern const char * nl_strerror_l(int err); + +#endif diff --git a/lib/utils.c b/lib/utils.c index 61c3d955b..c1c1b7242 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -25,10 +25,12 @@ */ #include +#include #include #include #include #include /* exit() */ +#include /** * Global variable indicating the desired level of debugging output. @@ -118,6 +120,28 @@ int __nl_read_num_str_file(const char *path, int (*cb)(long, const char *)) return 0; } + +const char *nl_strerror_l(int err) +{ + 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) + loc = newlocale(LC_MESSAGES_MASK, + "POSIX", (locale_t)0); + } + if (loc != (locale_t)0) { + buf = strerror_l(err, loc); + freelocale(loc); + } else { + buf = "newlocale() failed"; + } + + errno = errno_save; + return buf; +} /** @endcond */ /** diff --git a/libnl-3.sym b/libnl-3.sym index 4e09bdd67..9119e66e3 100644 --- a/libnl-3.sym +++ b/libnl-3.sym @@ -351,3 +351,8 @@ libnl_3_2_28 { global: nl_object_diff64; } libnl_3_2_27; + +libnl_3_2_29 { +global: + nl_strerror_l; +} libnl_3_2_28;