4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-17 03:49:46 +08:00
newlib-cygwin/newlib/libc/string/gnu_basename.c
Yaakov Selkowitz d67052321e 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.
2015-04-23 21:57:07 +02:00

27 lines
664 B
C

#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 */