diff options
author | Yaakov Selkowitz <yselkowi@redhat.com> | 2015-03-25 18:19:38 -0500 |
---|---|---|
committer | Yaakov Selkowitz <yselkowi@redhat.com> | 2015-03-30 13:10:40 -0500 |
commit | 779ddb0b4874afc80c13cb1c2afe45c68db2fdce (patch) | |
tree | b0a2f74ba00c1005bbb2cdec84ce209fc214e954 /newlib/libc/string/gnu_basename.c | |
parent | 98209e8e304e40a352bac5703a597ed66628d084 (diff) | |
download | cygnal-779ddb0b4874afc80c13cb1c2afe45c68db2fdce.tar.gz cygnal-779ddb0b4874afc80c13cb1c2afe45c68db2fdce.tar.bz2 cygnal-779ddb0b4874afc80c13cb1c2afe45c68db2fdce.zip |
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/gnu_basename.c')
-rw-r--r-- | newlib/libc/string/gnu_basename.c | 26 |
1 files changed, 26 insertions, 0 deletions
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 */ |