1From ccf93148aa3587dd98a02e253cdc42a7af14df1e Mon Sep 17 00:00:00 2001
2From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
3Date: Sat, 29 Aug 2020 16:04:15 +0200
4Subject: [PATCH] Provide replacement function for strerror_l()
5
6strerror_l() is not implemented in some C libraries, such as uClibc,
7so let's provide a simple replacement function that falls back on
8strerror().
9
10Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
11---
12 configure.ac         | 2 ++
13 src/plugins/crypto.c | 7 +++++++
14 src/utils/module.c   | 8 ++++++++
15 3 files changed, 17 insertions(+)
16
17diff --git a/configure.ac b/configure.ac
18index c2d22c2..36aeb51 100644
19--- a/configure.ac
20+++ b/configure.ac
21@@ -137,6 +137,8 @@ AC_CHECK_HEADERS([dlfcn.h string.h unistd.h sys/fcntl.h sys/ioctl.h linux/random
22                  [LIBBLOCKDEV_SOFT_FAILURE([Header file $ac_header not found.])],
23                  [])
24
25+AC_CHECK_FUNCS([strerror_l])
26+
27 AC_ARG_WITH([bcache],
28     AS_HELP_STRING([--with-bcache], [support bcache @<:@default=yes@:>@]),
29     [],
30diff --git a/src/plugins/crypto.c b/src/plugins/crypto.c
31index f4a2e8f..c1bd7b5 100644
32--- a/src/plugins/crypto.c
33+++ b/src/plugins/crypto.c
34@@ -52,6 +52,13 @@
35
36 #define UNUSED __attribute__((unused))
37
38+#if !defined(HAVE_STRERROR_L)
39+static char *strerror_l(int errnum, locale_t locale UNUSED)
40+{
41+	return strerror(errnum);
42+}
43+#endif
44+
45 /**
46  * SECTION: crypto
47  * @short_description: plugin for operations with encrypted devices
48diff --git a/src/utils/module.c b/src/utils/module.c
49index 9750e24..086bec0 100644
50--- a/src/utils/module.c
51+++ b/src/utils/module.c
52@@ -27,6 +27,14 @@
53
54 #include "module.h"
55
56+#define UNUSED __attribute__((unused))
57+
58+#if !defined(HAVE_STRERROR_L)
59+static char *strerror_l(int errnum, locale_t locale UNUSED)
60+{
61+	return strerror(errnum);
62+}
63+#endif
64
65 /**
66  * bd_utils_module_error_quark: (skip)
67--
682.26.2
69
70