diff --git a/lib/strlcat.c b/lib/strlcat.c index 14c53a1..8a9f2d7 100644 --- a/lib/strlcat.c +++ b/lib/strlcat.c @@ -16,6 +16,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#include +#ifndef HAVE_STRLCAT + #include #include @@ -27,7 +31,7 @@ * If retval >= dsize, truncation occurred. */ size_t -strlcat(char *dst, const char *src, size_t dsize) +__strlcat(char *dst, const char *src, size_t dsize) { const char *odst = dst; const char *osrc = src; @@ -53,3 +57,7 @@ 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 e9a7fe4..8918e68 100644 --- a/lib/strlcpy.c +++ b/lib/strlcpy.c @@ -16,6 +16,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#include +#ifndef HAVE_STRLCPY + #include #include @@ -25,7 +29,7 @@ * Returns strlen(src); if retval >= dsize, truncation occurred. */ size_t -strlcpy(char *dst, const char *src, size_t dsize) +__strlcpy(char *dst, const char *src, size_t dsize) { const char *osrc = src; size_t nleft = dsize; @@ -48,3 +52,7 @@ 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/src/.gitignore b/src/.gitignore index 9a0d0d8..e6d3441 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -6,5 +6,6 @@ logger syslogd syslog_tst tsyslogd +libcompat.la libsyslog.la libsyslog.pc diff --git a/src/Makefile.am b/src/Makefile.am index e393399..5156648 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,7 @@ bin_PROGRAMS = logger sbin_PROGRAMS = syslogd klogd lib_LTLIBRARIES = libsyslog.la +noinst_LTLIBRARIES = libcompat.la AM_CFLAGS = -W -Wall -Wextra AM_CFLAGS += -Wno-unused-result -Wno-unused-parameter -fno-strict-aliasing @@ -39,11 +40,15 @@ logger_CPPFLAGS = $(AM_CPPFLAGS) -D_XOPEN_SOURCE=600 logger_LDADD = $(LIBS) $(LIBOBJS) logger_LDADD += libsyslog.la +# Convenience library for libsyslog instead of linking with $(LTLIBOBJS), +# which would pull in pidfile() and other (strong) symbols as well. +libcompat_la_SOURCES = ../lib/strlcpy.c ../lib/strlcat.c + pkgconfigdir = $(libdir)/pkgconfig pkgincludedir = $(includedir)/syslog pkgconfig_DATA = libsyslog.pc pkginclude_HEADERS = syslog.h libsyslog_la_SOURCES = syslog.c syslog.h libsyslog_la_CPPFLAGS = $(AM_CPPFLAGS) -D_XOPEN_SOURCE=600 -libsyslog_la_LIBADD = $(LTLIBOBJS) libsyslog_la_LDFLAGS = $(AM_LDFLAGS) -version-info 0:0:0 +libsyslog_la_LIBADD = libcompat.la diff --git a/src/compat.h b/src/compat.h index 54b614d..a867636 100644 --- a/src/compat.h +++ b/src/compat.h @@ -46,6 +46,17 @@ */ #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;