Don't re-define strlcpy/strlcat with >=glibc-2.38

`>=glibc-2.38` implements strlcpy, strlcat, etc so check for those functions
with Meson and don't provide conflicting prototypes.

Technically, it doesn't need _GNU_SOURCE, but it's easier because it's not
clear right now what glibc wants to guard it with. Note that these are in
POSIX next anyway.

Fixes: https://github.com/OpenRC/openrc/issues/643
Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sam James 2023-08-30 02:32:13 +01:00 committed by Mike Frysinger
parent 86efc43d0e
commit c1cd3c9830
3 changed files with 6 additions and 7 deletions

View File

@ -203,6 +203,10 @@ if cc.has_function('close_range', prefix: '#define _GNU_SOURCE\n#include <unistd
add_project_arguments('-DHAVE_CLOSE_RANGE_CLOEXEC', language: 'c') add_project_arguments('-DHAVE_CLOSE_RANGE_CLOEXEC', language: 'c')
endif endif
if cc.has_function('strlcpy', prefix: '#define _GNU_SOURCE\n#include <string.h>')
add_project_arguments('-DHAVE_STRLCPY', language: 'c')
endif
incdir = include_directories('src/shared') incdir = include_directories('src/shared')
einfo_incdir = include_directories('src/libeinfo') einfo_incdir = include_directories('src/libeinfo')
rc_incdir = include_directories('src/librc') rc_incdir = include_directories('src/librc')

View File

@ -146,9 +146,7 @@ static const char *const color_terms[] = {
}; };
#endif #endif
/* strlcat and strlcpy are nice, shame glibc does not define them */ #ifndef HAVE_STRLCPY
#ifdef __GLIBC__
# if !defined (__UCLIBC__) && !defined (__dietlibc__)
static size_t static size_t
strlcat(char *dst, const char *src, size_t size) strlcat(char *dst, const char *src, size_t size)
{ {
@ -177,7 +175,6 @@ strlcat(char *dst, const char *src, size_t size)
return dst_n + (s - src); return dst_n + (s - src);
} }
#endif #endif
#endif
static bool static bool
yesno(const char *value) yesno(const char *value)

View File

@ -37,11 +37,9 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#ifdef __GLIBC__ #ifndef HAVE_STRLCPY
# if !defined (__UCLIBC__) && !defined (__dietlibc__)
# define strlcpy(dst, src, size) snprintf(dst, size, "%s", src) # define strlcpy(dst, src, size) snprintf(dst, size, "%s", src)
#endif #endif
#endif
#ifndef timespecsub #ifndef timespecsub
#define timespecsub(tsp, usp, vsp) \ #define timespecsub(tsp, usp, vsp) \