From 48dfe3974710aa9807980852aa5f46e1c311c579 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Sat, 12 Oct 2024 13:48:56 -0700 Subject: [PATCH] Fallback to strerror() when strerror_l() isn't available Some C libraries, such as uClibc, do not provide strerror_l() in which case we fallback to strerror(). Reviewed-by: Tino Reichardt Signed-off-by: Brian Behlendorf Closes #16636 Closes #16640 --- config/user.m4 | 2 +- include/libzutil.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/user.m4 b/config/user.m4 index badd920d2..4e31745a2 100644 --- a/config/user.m4 +++ b/config/user.m4 @@ -33,7 +33,7 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [ ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV ZFS_AC_CONFIG_USER_ZFSEXEC - AC_CHECK_FUNCS([execvpe issetugid mlockall strlcat strlcpy gettid]) + AC_CHECK_FUNCS([execvpe issetugid mlockall strerror_l strlcat strlcpy gettid]) AC_SUBST(RM) ]) diff --git a/include/libzutil.h b/include/libzutil.h index e2108ceea..f8712340c 100644 --- a/include/libzutil.h +++ b/include/libzutil.h @@ -276,7 +276,11 @@ _LIBZUTIL_H void update_vdev_config_dev_sysfs_path(nvlist_t *nv, * Thread-safe strerror() for use in ZFS libraries */ static inline char *zfs_strerror(int errnum) { +#ifdef HAVE_STRERROR_L return (strerror_l(errnum, uselocale(0))); +#else + return (strerror(errnum)); +#endif } #ifdef __cplusplus