User programs are forbidden to use names of functions provided by the standard library [1]. Since glibc 2.38, strlcpy() and strlcat() are part of the system library. Rename our own functions to libmp_strlcpy() and libmp_strlcat(), respectively, and only use the short names if the C library doesn't have them. It turns out that msul libc has always had strlcat() and strlcpy(), so use the system library function with musl, too. [1] https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html --- libmpathutil/util.c | 4 ++-- libmpathutil/util.h | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libmpathutil/util.c b/libmpathutil/util.c index 9c422f1..136aa59 100644 --- a/libmpathutil/util.c +++ b/libmpathutil/util.c @@ -121,7 +121,7 @@ get_word (const char *sentence, char **word) return skip + len; } -size_t strlcpy(char * restrict dst, const char * restrict src, size_t size) +size_t libmp_strlcpy(char * restrict dst, const char * restrict src, size_t size) { size_t bytes = 0; char ch; @@ -138,7 +138,7 @@ size_t strlcpy(char * restrict dst, const char * restrict src, size_t size) return bytes; } -size_t strlcat(char * restrict dst, const char * restrict src, size_t size) +size_t libmp_strlcat(char * restrict dst, const char * restrict src, size_t size) { size_t bytes = 0; char ch; diff --git a/libmpathutil/util.h b/libmpathutil/util.h index c19f749..7bad855 100644 --- a/libmpathutil/util.h +++ b/libmpathutil/util.h @@ -12,6 +12,10 @@ #include <stdio.h> #include <libudev.h> +#ifndef __GLIBC_PREREQ +#define __GLIBC_PREREQ(x, y) 0 +#endif + size_t strchop(char *); const char *libmp_basename(const char *filename); @@ -22,8 +26,12 @@ int basenamecpy (const char *src, char *dst, size_t size); int filepresent (const char *run); char *get_next_string(char **temp, const char *split_char); int get_word (const char * sentence, char ** word); -size_t strlcpy(char * restrict dst, const char * restrict src, size_t size); -size_t strlcat(char * restrict dst, const char * restrict src, size_t size); +size_t libmp_strlcpy(char * restrict dst, const char * restrict src, size_t size); +size_t libmp_strlcat(char * restrict dst, const char * restrict src, size_t size); +#if defined(__GLIBC__) && ! (__GLIBC_PREREQ(2, 38)) +#define strlcpy(dst, src, size) libmp_strlcpy(dst, src, size) +#define strlcat(dst, src, size) libmp_strlcat(dst, src, size) +#endif dev_t parse_devt(const char *dev_t); char *convert_dev(char *dev, int is_path_device); void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached); @@ -62,9 +70,6 @@ struct scandir_result { }; void free_scandir_result(struct scandir_result *); -#ifndef __GLIBC_PREREQ -#define __GLIBC_PREREQ(x, y) 0 -#endif /* * ffsll() is also available on glibc < 2.27 if _GNU_SOURCE is defined. * But relying on that would require that every program using this header file -- 2.46.0