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 <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2020-01-19 09:07:14 +01:00
parent de4c349930
commit 5fce3001ed
5 changed files with 9 additions and 45 deletions

View File

@ -31,9 +31,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <config.h>
#ifndef HAVE_PIDFILE
#define _GNU_SOURCE /* Needed with GLIBC to get asprintf() */
#include <sys/stat.h> /* utimensat() */
#include <sys/time.h> /* utimensat() on *BSD */
@ -42,11 +39,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#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 */

View File

@ -16,10 +16,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <compat.h>
#ifndef HAVE_STRLCAT
#include <sys/types.h>
#include <string.h>
@ -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 */

View File

@ -16,10 +16,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <compat.h>
#ifndef HAVE_STRLCPY
#include <sys/types.h>
#include <string.h>
@ -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 */

View File

@ -15,9 +15,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#ifndef HAVE_UTIMENSAT
#include <errno.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
@ -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 */

View File

@ -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)
{