1 #ifndef _NO_BASENAME
2 /* Copyright 2015 Red Hat, Inc.
3  * Permission to use, copy, modify, and distribute this software
4  * is freely granted, provided that this notice is preserved.
5  */
6 
7 /* The differences with the POSIX version (unix/basename.c):
8  * - declared in <string.h> (instead of <libgen.h>);
9  * - the argument is never modified, and therefore is marked const;
10  * - the empty string is returned if path is an empty string, "/", or ends
11  *   with a trailing slash.
12  */
13 
14 #define _GNU_SOURCE
15 #include <string.h>
16 
17 __typeof(basename) __gnu_basename;
18 
19 char *
__gnu_basename(const char * path)20 __gnu_basename (const char *path)
21 {
22   char *p;
23   if ((p = strrchr (path, '/')))
24     return p + 1;
25   return (char *) path;
26 }
27 
28 #endif /* !_NO_BASENAME  */
29