From c023c1517a0b8adb3c24ddc6dfa30e4242076ee8 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Wed, 16 May 2012 06:36:19 +0200 Subject: Provide missing basename_r and dirname_r Some systems (e.g.: NetBSD) do not have thread-safe basename(3) and dirname(3). This is fine with OpenGroup's Single Unix Specification which allows these functions to use static storage. Unfortunately, glusterfs uses them a lot and assume thread-safety. This patch brings FreeBSD's thread-safe basename_r(3) and dirname_r(3) in the contrib directory, and tweaks the build process so that NetBSD builds use them instead of libc basename(3) and dirname(3) BUG: 764655 Change-Id: Ic9a159fffdc7bacc9408f8e90854e4c2db81930c Signed-off-by: Emmanuel Dreyfus Reviewed-on: http://review.gluster.com/3320 Tested-by: Gluster Build System Reviewed-by: Kaleb KEITHLEY Reviewed-by: Anand Avati --- libglusterfs/src/compat.c | 7 +++++++ libglusterfs/src/compat.h | 16 +++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c index 2dcd56a41..99a0041a5 100644 --- a/libglusterfs/src/compat.c +++ b/libglusterfs/src/compat.c @@ -550,3 +550,10 @@ strnlen(const char *string, size_t maxlen) return len; } #endif /* STRNLEN */ + +#ifdef THREAD_UNSAFE_BASENAME +#include "../../contrib/libgen/basename_r.c" +#endif +#ifdef THREAD_UNSAFE_DIRNAME +#include "../../contrib/libgen/dirname_r.c" +#endif diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h index 24ceed22e..a6eec2ded 100644 --- a/libglusterfs/src/compat.h +++ b/libglusterfs/src/compat.h @@ -107,13 +107,6 @@ enum { #define F_SETLK64 F_SETLK #define F_SETLKW64 F_SETLKW -#ifdef __NetBSD__ -char *basename_r(const char *); -char *dirname_r(char *); - -#define basename(path) basename_r(path) -#define dirname(path) dirname_r(path) -#endif /* __NetBSD__ */ #endif /* GF_BSD_HOST_OS */ #ifdef GF_DARWIN_HOST_OS @@ -341,6 +334,15 @@ dirent_size (struct dirent *entry) return size; } +#ifdef THREAD_UNSAFE_BASENAME +char *basename_r(const char *); +#define basename(path) basename_r(path) +#endif /* THREAD_UNSAFE_BASENAME */ + +#ifdef THREAD_UNSAFE_DIRNAME +char *dirname_r(const char *path); +#define dirname(path) dirname_r(path) +#endif /* THREAD_UNSAFE_DIRNAME */ #ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC /* Linux, Solaris, Cygwin */ -- cgit