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 <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2015-04-22 10:05:16 +02:00
parent e6101f3008
commit 97a5dda2b0
3 changed files with 34 additions and 12 deletions

View File

@ -1,3 +1,11 @@
2015-04-22 Corinna Vinschen <vinschen@redhat.com>
* 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 <nickc@redhat.com> 2015-04-09 Nick Clifton <nickc@redhat.com>
* libc/machine/rx/memchr.S: Add non-string insn using version. * libc/machine/rx/memchr.S: Add non-string insn using version.

View File

@ -12,8 +12,20 @@
extern "C" { extern "C" {
#endif #endif
/* There are two common basename variants. If you do NOT #include <libgen.h>
and you do
#define _GNU_SOURCE
#include <string.h>
you get the GNU version. Otherwise you get the POSIX versionfor which you
should #include <libgen.h>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 *)); char *_EXFUN(basename, (char *));
#define _BASENAME_DEFINED
char *_EXFUN(dirname, (char *)); char *_EXFUN(dirname, (char *));
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -163,18 +163,20 @@ int _EXFUN(strtosigno, (const char *__name));
(char *) memcpy (__out, __in, __len-1);})) (char *) memcpy (__out, __in, __len-1);}))
#endif /* _GNU_SOURCE && __GNUC__ */ #endif /* _GNU_SOURCE && __GNUC__ */
/* There are two common basename variants. If you #include <libgen.h> /* There are two common basename variants. If you do NOT #include <libgen.h>
first, you get the POSIX version; otherwise you get the GNU version. and you do
POSIX requires that #undef basename will still let you
invoke the underlying function, but that requires gcc support. */ #define _GNU_SOURCE
#if __GNU_VISIBLE && !defined(_BASENAME_DEFINED) #include <string.h>
# ifdef __GNUC__
char *_EXFUN(basename,(const char *)) you get the GNU version. Otherwise you get the POSIX versionfor which you
__asm__ (__ASMNAME ("__gnu_basename")) __nonnull(1); should #include <libgen.h>i for the function prototype. POSIX requires that
# else #undef basename will still let you invoke the underlying function. However,
char *_EXFUN(__gnu_basename,(const char *)); 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 # define basename __gnu_basename
# endif
#endif #endif
#include <sys/string.h> #include <sys/string.h>