From 6a7420b6dc0b431a5f67aa547d8d84d1f40a6c67 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Tue, 4 Mar 2008 11:55:55 +0000 Subject: [PATCH] detect basename() function, include small compat func if missing --- configure.ac | 4 ++-- include/system.h | 6 ++++++ src/system.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 6036a8f..f747860 100644 --- a/configure.ac +++ b/configure.ac @@ -66,7 +66,7 @@ if test x"$GCC" = xyes; then fi dnl Checks for header files. -AC_CHECK_HEADERS([crypt.h sys/param.h sys/socket.h]) +AC_CHECK_HEADERS([crypt.h sys/param.h sys/socket.h libgen.h]) dnl ucred.h may have prereqs AC_CHECK_HEADERS([sys/ucred.h], [], [], [ #ifdef HAVE_SYS_TYPES_H @@ -92,7 +92,7 @@ AC_TYPE_UINT64_T ]) dnl Checks for library functions. -AC_CHECK_FUNCS(strlcpy strlcat getpeereid getpeerucred) +AC_CHECK_FUNCS(strlcpy strlcat getpeereid getpeerucred basename) AC_SEARCH_LIBS(crypt, crypt, [], AC_MSG_ERROR([crypt not found])) AC_SEARCH_LIBS(clock_gettime, rt) diff --git a/include/system.h b/include/system.h index 2564302..48e45e7 100644 --- a/include/system.h +++ b/include/system.h @@ -53,6 +53,9 @@ #ifdef HAVE_CRYPT_H #include #endif +#ifdef HAVE_LIBGEN_H +#include +#endif /* how to specify array with unknown length */ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) @@ -137,6 +140,9 @@ size_t strlcat(char *dst, const char *src, size_t n) _MUSTCHECK; #ifndef HAVE_GETPEEREID int getpeereid(int fd, uid_t *uid_p, gid_t *gid_p) _MUSTCHECK; #endif +#ifndef HAVE_BASENAME +const char *basename(const char *path); +#endif /* * memcpy() optimization - improves hash.c. diff --git a/src/system.c b/src/system.c index 4dc1868..5107001 100644 --- a/src/system.c +++ b/src/system.c @@ -89,3 +89,15 @@ int getpeereid(int fd, uid_t *uid_p, gid_t *gid_p) } #endif /* !HAVE_GETPEEREID */ +#ifndef HAVE_BASENAME +const char *basename(const char *path) +{ + const char *p; + if (path == NULL || path[0] == 0) + return "."; + if ((p = strrchr(path, '/')) != NULL) + return p[1] ? p + 1 : p; + return path; +} +#endif + -- 2.39.5