From 84e4cb880afd04de3693a7b61f53aa91c575b101 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 22 Apr 2015 10:05:16 +0200 Subject: [PATCH] Fix basename prototype collision string.h vs libgen.h * libc/include/libgen.h (basename): Drop defining _BASENAME_DEFINED. Always define macro basename. Add comment to explain why. * libc/include/string.h (basename): Check for basename instead of _BASENAME_DEFINED. Drop __GNUC__ branch, always use basename macro. Change comment to explain why. Add nonnull function attribute. Signed-off-by: Corinna Vinschen --- newlib/ChangeLog | 8 ++++++++ newlib/libc/include/libgen.h | 14 +++++++++++++- newlib/libc/include/string.h | 24 +++++++++++++----------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index bca127755..edf4a7fce 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,11 @@ +2015-04-22 Corinna Vinschen + + * libc/include/libgen.h (basename): Drop defining _BASENAME_DEFINED. + Always define macro basename. Add comment to explain why. + * libc/include/string.h (basename): Check for basename instead of + _BASENAME_DEFINED. Drop __GNUC__ branch, always use basename macro. + Change comment to explain why. Add nonnull function attribute. + 2015-04-09 Nick Clifton * libc/machine/rx/memchr.S: Add non-string insn using version. diff --git a/newlib/libc/include/libgen.h b/newlib/libc/include/libgen.h index 8360a22f9..de70b5b2f 100644 --- a/newlib/libc/include/libgen.h +++ b/newlib/libc/include/libgen.h @@ -12,8 +12,20 @@ extern "C" { #endif +/* There are two common basename variants. If you do NOT #include + and you do + + #define _GNU_SOURCE + #include + + you get the GNU version. Otherwise you get the POSIX versionfor which you + should #include i for the function prototype. POSIX requires that + #undef basename will still let you invoke the underlying function. However, + this also implies that the POSIX version is used in this case. That's made + sure here. */ +#undef basename +#define basename basename char *_EXFUN(basename, (char *)); -#define _BASENAME_DEFINED char *_EXFUN(dirname, (char *)); #ifdef __cplusplus diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h index 9e11e5c51..92e08aebc 100644 --- a/newlib/libc/include/string.h +++ b/newlib/libc/include/string.h @@ -163,18 +163,20 @@ int _EXFUN(strtosigno, (const char *__name)); (char *) memcpy (__out, __in, __len-1);})) #endif /* _GNU_SOURCE && __GNUC__ */ -/* There are two common basename variants. If you #include - first, you get the POSIX version; otherwise you get the GNU version. - POSIX requires that #undef basename will still let you - invoke the underlying function, but that requires gcc support. */ -#if __GNU_VISIBLE && !defined(_BASENAME_DEFINED) -# ifdef __GNUC__ -char *_EXFUN(basename,(const char *)) - __asm__ (__ASMNAME ("__gnu_basename")) __nonnull(1); -# else -char *_EXFUN(__gnu_basename,(const char *)); +/* There are two common basename variants. If you do NOT #include + and you do + + #define _GNU_SOURCE + #include + + you get the GNU version. Otherwise you get the POSIX versionfor which you + should #include i for the function prototype. POSIX requires that + #undef basename will still let you invoke the underlying function. However, + this also implies that the POSIX version is used in this case. That's made + sure here. */ +#if __GNU_VISIBLE && !defined(basename) +char *_EXFUN(__nonnull (1) __gnu_basename,(const char *)); # define basename __gnu_basename -# endif #endif #include