From 5fce3001ed74f306fb55a5adb2adc4010515f523 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 19 Jan 2020 09:07:14 +0100 Subject: [PATCH] Simplify handling of replacement functions; strlcpy() & C:o - Drop weak bindings, use simple #define in compat.h instead - No need to #ifdef sources with HAVE_foo, configure handles this for us - Move utimensat() declaration to compat.h from pidfile.c to be consistent With these changes we can let libsyslog link with the replacement objs, just like syslogd and logger does. Because even if the C-library does *not* have strlcpy() & C:o *and* an application has a local copy of any of these APIs, our versions are prefixed with __ in the symbol table. Signed-off-by: Joachim Nilsson --- lib/pidfile.c | 12 +----------- lib/strlcat.c | 8 -------- lib/strlcpy.c | 8 -------- lib/utimensat.c | 7 ------- src/compat.h | 19 ++++++++----------- 5 files changed, 9 insertions(+), 45 deletions(-) diff --git a/lib/pidfile.c b/lib/pidfile.c index 8b5f517..a26de73 100644 --- a/lib/pidfile.c +++ b/lib/pidfile.c @@ -31,9 +31,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include -#ifndef HAVE_PIDFILE - #define _GNU_SOURCE /* Needed with GLIBC to get asprintf() */ #include /* utimensat() */ #include /* utimensat() on *BSD */ @@ -42,11 +39,7 @@ #include #include #include -#include "compat.h" - -#ifndef HAVE_UTIMENSAT -int utimensat(int dirfd, const char *pathname, const struct timespec ts[2], int flags); -#endif +#include "compat.h" /* For utimensat() if missing */ static char *pidfile_path = NULL; static pid_t pidfile_pid = 0; @@ -139,6 +132,3 @@ pidfile_cleanup(void) pidfile_path = NULL; } } - -weak_alias(__pidfile, pidfile); -#endif /* HAVE_PIDFILE */ diff --git a/lib/strlcat.c b/lib/strlcat.c index 8a9f2d7..f5fca67 100644 --- a/lib/strlcat.c +++ b/lib/strlcat.c @@ -16,10 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include -#ifndef HAVE_STRLCAT - #include #include @@ -57,7 +53,3 @@ __strlcat(char *dst, const char *src, size_t dsize) return(dlen + (src - osrc)); /* count does not include NUL */ } - -weak_alias(__strlcat, strlcat); - -#endif /* HAVE_STRLCAT */ diff --git a/lib/strlcpy.c b/lib/strlcpy.c index 8918e68..d6bcc28 100644 --- a/lib/strlcpy.c +++ b/lib/strlcpy.c @@ -16,10 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include -#ifndef HAVE_STRLCPY - #include #include @@ -52,7 +48,3 @@ __strlcpy(char *dst, const char *src, size_t dsize) return(src - osrc - 1); /* count does not include NUL */ } - -weak_alias(__strlcpy, strlcpy); - -#endif /* HAVE_STRLCPY */ diff --git a/lib/utimensat.c b/lib/utimensat.c index b68ce0e..b4ea01c 100644 --- a/lib/utimensat.c +++ b/lib/utimensat.c @@ -15,9 +15,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#ifndef HAVE_UTIMENSAT - #include #ifdef HAVE_FCNTL_H #include @@ -47,7 +44,3 @@ __utimensat(int dirfd, const char *pathname, const struct timespec ts[2], int fl return ret; } - -weak_alias(__utimensat, utimensat); - -#endif /* HAVE_UTIMENSAT */ diff --git a/src/compat.h b/src/compat.h index 1ef1bf0..a5b20ad 100644 --- a/src/compat.h +++ b/src/compat.h @@ -47,17 +47,6 @@ */ #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) -/* - * The functions strlcat() and strlcpy() may be available in either - * the C library or another library the user links their application - * with. So we must declare them as "weak" symbols in libsyslog. - */ -#ifndef weak_alias -# define weak_alias(name, aliasname) _weak_alias (name, aliasname) -# define _weak_alias(name, aliasname) \ - extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) -#endif - /* Pthread wrapper for BSD LWP mutexes */ typedef pthread_mutex_t mutex_t; @@ -73,17 +62,25 @@ typedef pthread_mutex_t mutex_t; #endif #ifndef HAVE_STRLCPY +#define strlcpy __strlcpy size_t strlcpy(char *dst, const char *src, size_t siz); #endif #ifndef HAVE_STRLCAT +#define strlcat __strlcat size_t strlcat(char *dst, const char *src, size_t siz); #endif #ifndef HAVE_PIDFILE +#define pidfile __pidfile int pidfile(const char *basename); #endif +#ifndef HAVE_UTIMENSAT +#define utimensat __utimensat +int utimensat(int dirfd, const char *pathname, const struct timespec ts[2], int flags); +#endif + #ifndef HAVE_GETPROGNAME static inline char *getprogname(void) {