string: add GNU basename(3)
* libc/include/libgen.h (_BASENAME_DEFINED): Define. * libc/include/string.h (basename): Declare. * libc/string/Makefile.am (ELIX_4_SOURCES): Add gnu_basename.c. * libc/string/Makefile.in: Regenerate. * libc/string/gnu_basename.c: New file.
This commit is contained in:
parent
d4f8c94a9b
commit
d67052321e
|
@ -1,3 +1,11 @@
|
|||
2015-03-30 Yaakov Selkowitz <yselkowi@redhat.com>
|
||||
|
||||
* libc/include/libgen.h (_BASENAME_DEFINED): Define.
|
||||
* libc/include/string.h (basename): Declare.
|
||||
* libc/string/Makefile.am (ELIX_4_SOURCES): Add gnu_basename.c.
|
||||
* libc/string/Makefile.in: Regenerate.
|
||||
* libc/string/gnu_basename.c: New file.
|
||||
|
||||
2015-03-23 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
||||
|
||||
* libc/include/sys/tree.h: New file.
|
||||
|
|
|
@ -13,6 +13,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
char *_EXFUN(basename, (char *));
|
||||
#define _BASENAME_DEFINED
|
||||
char *_EXFUN(dirname, (char *));
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -163,6 +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 <libgen.h>
|
||||
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 *));
|
||||
# define basename __gnu_basename
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <sys/string.h>
|
||||
|
||||
_END_STD_C
|
||||
|
|
|
@ -102,6 +102,7 @@ if ELIX_LEVEL_3
|
|||
ELIX_4_SOURCES =
|
||||
else
|
||||
ELIX_4_SOURCES = \
|
||||
gnu_basename.c \
|
||||
memmem.c \
|
||||
memrchr.c \
|
||||
rawmemchr.c \
|
||||
|
|
|
@ -118,7 +118,8 @@ am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \
|
|||
@ELIX_LEVEL_1_FALSE@ lib_a-wcpcpy.$(OBJEXT) \
|
||||
@ELIX_LEVEL_1_FALSE@ lib_a-wcpncpy.$(OBJEXT) \
|
||||
@ELIX_LEVEL_1_FALSE@ lib_a-wcsdup.$(OBJEXT)
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_3 = lib_a-memmem.$(OBJEXT) \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_3 = lib_a-gnu_basename.$(OBJEXT) \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-memmem.$(OBJEXT) \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-memrchr.$(OBJEXT) \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-rawmemchr.$(OBJEXT) \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-wcscasecmp.$(OBJEXT) \
|
||||
|
@ -145,7 +146,8 @@ am__objects_4 = bcopy.lo bzero.lo index.lo memchr.lo memcmp.lo \
|
|||
@ELIX_LEVEL_1_FALSE@ stpcpy.lo stpncpy.lo strndup.lo \
|
||||
@ELIX_LEVEL_1_FALSE@ strcasestr.lo strchrnul.lo strndup_r.lo \
|
||||
@ELIX_LEVEL_1_FALSE@ wcpcpy.lo wcpncpy.lo wcsdup.lo
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_6 = memmem.lo \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_6 = gnu_basename.lo \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ memmem.lo \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ memrchr.lo \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ rawmemchr.lo \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ wcscasecmp.lo \
|
||||
|
@ -410,6 +412,7 @@ GENERAL_SOURCES = \
|
|||
|
||||
@ELIX_LEVEL_1_TRUE@ELIX_2_SOURCES =
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ELIX_4_SOURCES = \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ gnu_basename.c \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ memmem.c \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ memrchr.c \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ rawmemchr.c \
|
||||
|
@ -998,6 +1001,12 @@ lib_a-wcsdup.o: wcsdup.c
|
|||
lib_a-wcsdup.obj: wcsdup.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcsdup.obj `if test -f 'wcsdup.c'; then $(CYGPATH_W) 'wcsdup.c'; else $(CYGPATH_W) '$(srcdir)/wcsdup.c'; fi`
|
||||
|
||||
lib_a-gnu_basename.o: gnu_basename.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gnu_basename.o `test -f 'gnu_basename.c' || echo '$(srcdir)/'`gnu_basename.c
|
||||
|
||||
lib_a-gnu_basename.obj: gnu_basename.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-gnu_basename.obj `if test -f 'gnu_basename.c'; then $(CYGPATH_W) 'gnu_basename.c'; else $(CYGPATH_W) '$(srcdir)/gnu_basename.c'; fi`
|
||||
|
||||
lib_a-memmem.o: memmem.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-memmem.o `test -f 'memmem.c' || echo '$(srcdir)/'`memmem.c
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef _NO_BASENAME
|
||||
/* Copyright 2015 Red Hat, Inc.
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
/* The differences with the POSIX version (unix/basename.c):
|
||||
* - declared in <string.h> (instead of <libgen.h>);
|
||||
* - the argument is never modified, and therefore is marked const;
|
||||
* - the empty string is returned if path is an empty string, "/", or ends
|
||||
* with a trailing slash.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
_DEFUN (__gnu_basename, (path),
|
||||
const char *path)
|
||||
{
|
||||
char *p;
|
||||
if ((p = strrchr (path, '/')))
|
||||
return p + 1;
|
||||
return path;
|
||||
}
|
||||
|
||||
#endif /* !_NO_BASENAME */
|
Loading…
Reference in New Issue