Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / unix / basename.c
blob7a28ac51b251efae5a101ba254ff4764afff6bc9
1 #ifndef _NO_BASENAME
2 /* Copyright 2005 Shaun Jackman
3 * Permission to use, copy, modify, and distribute this software
4 * is freely granted, provided that this notice is preserved.
5 */
7 #include <libgen.h>
8 #include <string.h>
10 char*
11 basename (char *path)
13 char *p;
14 if( path == NULL || *path == '\0' )
15 return ".";
16 p = path + strlen(path) - 1;
17 while( *p == '/' ) {
18 if( p == path )
19 return path;
20 *p-- = '\0';
22 while( p >= path && *p != '/' )
23 p--;
24 return p + 1;
27 #endif /* !_NO_BASENAME */