diff options
author | Yaakov Selkowitz <yselkowi@redhat.com> | 2015-03-26 02:19:38 +0300 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2015-04-23 22:57:07 +0300 |
commit | d67052321ec17d82bd7da35ae3fd87eecd7b376f (patch) | |
tree | c2f220da7864776b214db15fd99936a77e47f051 /newlib/libc/string | |
parent | d4f8c94a9b62706d88f8b6b80697023ab32ae497 (diff) |
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.
Diffstat (limited to 'newlib/libc/string')
-rw-r--r-- | newlib/libc/string/Makefile.am | 1 | ||||
-rw-r--r-- | newlib/libc/string/Makefile.in | 13 | ||||
-rw-r--r-- | newlib/libc/string/gnu_basename.c | 26 |
3 files changed, 38 insertions, 2 deletions
diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am index e9adbe169..e73bfdccd 100644 --- a/newlib/libc/string/Makefile.am +++ b/newlib/libc/string/Makefile.am @@ -102,6 +102,7 @@ if ELIX_LEVEL_3 ELIX_4_SOURCES = else ELIX_4_SOURCES = \ + gnu_basename.c \ memmem.c \ memrchr.c \ rawmemchr.c \ diff --git a/newlib/libc/string/Makefile.in b/newlib/libc/string/Makefile.in index 255ee0704..bcebcbd62 100644 --- a/newlib/libc/string/Makefile.in +++ b/newlib/libc/string/Makefile.in @@ -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 diff --git a/newlib/libc/string/gnu_basename.c b/newlib/libc/string/gnu_basename.c new file mode 100644 index 000000000..46b92d0fd --- /dev/null +++ b/newlib/libc/string/gnu_basename.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 */ |