package/kernel/leds-apu2: add apu3 board detection
[openwrt/openwrt.git] / package / libs / libnl / patches / 0001-lib-Escape-usage-of-strerror_l-if-it-doesn-t-exist-i.patch
1 From 098a4cc35b0da4438b8b67a914edecebef5bb6a9 Mon Sep 17 00:00:00 2001
2 From: Alexey Brodkin <abrodkin@synopsys.com>
3 Date: Fri, 10 Mar 2017 13:22:14 +0300
4 Subject: [PATCH] lib: Escape usage of strerror_l() if it doesn't exist in libc
5
6 uClibc doesn't implement strerror_l() and thus libnl starting from
7 3.2.29 couldn't be compiled with it any longer.
8
9 To work-around that problem we'll just do a check on strerror_l()
10 availability during configuration and if it's not there just fall back
11 to locale-less strerror().
12
13 Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
14 Cc: Andre Draszik <adraszik@tycoint.com>
15 Cc: Thomas Haller <thaller@redhat.com>
16 ---
17
18 This patch is now accepted upstream and will be a part of the next libnl
19 release, see
20 https://github.com/thom311/libnl/commit/e15966ac7f3b43df2acf869f98089762807d0568
21
22 configure.ac | 2 ++
23 lib/utils.c | 8 +++++++-
24 src/lib/utils.c | 6 ++++++
25 3 files changed, 15 insertions(+), 1 deletion(-)
26
27 diff --git a/configure.ac b/configure.ac
28 index 68b285e5b15c..2739b997ee3a 100644
29 --- a/configure.ac
30 +++ b/configure.ac
31 @@ -121,6 +121,8 @@ fi
32
33 AC_CONFIG_SUBDIRS([doc])
34
35 +AC_CHECK_FUNCS([strerror_l])
36 +
37 AC_CONFIG_FILES([
38 Makefile
39 libnl-3.0.pc
40 diff --git a/lib/utils.c b/lib/utils.c
41 index fb350d13fd2f..06273c5b291e 100644
42 --- a/lib/utils.c
43 +++ b/lib/utils.c
44 @@ -30,7 +30,9 @@
45 #include <netlink/utils.h>
46 #include <linux/socket.h>
47 #include <stdlib.h> /* exit() */
48 +#ifdef HAVE_STRERROR_L
49 #include <locale.h>
50 +#endif
51
52 /**
53 * Global variable indicating the desired level of debugging output.
54 @@ -123,9 +125,10 @@ int __nl_read_num_str_file(const char *path, int (*cb)(long, const char *))
55
56 const char *nl_strerror_l(int err)
57 {
58 + const char *buf;
59 +#ifdef HAVE_STRERROR_L
60 int errno_save = errno;
61 locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0);
62 - const char *buf;
63
64 if (loc == (locale_t)0) {
65 if (errno == ENOENT)
66 @@ -140,6 +143,9 @@ const char *nl_strerror_l(int err)
67 }
68
69 errno = errno_save;
70 +#else
71 + buf = strerror(err);
72 +#endif
73 return buf;
74 }
75 /** @endcond */
76 diff --git a/src/lib/utils.c b/src/lib/utils.c
77 index 5878f279c364..feb1d4ef4056 100644
78 --- a/src/lib/utils.c
79 +++ b/src/lib/utils.c
80 @@ -81,6 +81,7 @@ void nl_cli_fatal(int err, const char *fmt, ...)
81 fprintf(stderr, "\n");
82 } else {
83 char *buf;
84 +#ifdef HAVE_STRERROR_L
85 locale_t loc = newlocale(LC_MESSAGES_MASK, "", (locale_t)0);
86 if (loc == (locale_t)0) {
87 if (errno == ENOENT)
88 @@ -91,9 +92,14 @@ void nl_cli_fatal(int err, const char *fmt, ...)
89 }
90 if (loc != (locale_t)0)
91 buf = strerror_l(err, loc);
92 +#else
93 + buf = strerror(err);
94 +#endif
95 fprintf(stderr, "%s\n", buf);
96 +#ifdef HAVE_STRERROR_L
97 if (loc != (locale_t)0)
98 freelocale(loc);
99 +#endif
100 }
101
102 exit(abs(err));
103 --
104 2.7.4
105