Cygwin: mmap: use 64K pages for bookkeeping, second attempt
[newlib-cygwin.git] / newlib / libc / unix / dirname.c
blob7d8d6f024e7c2b28a2b0b5768477e94e44f27b71
1 #ifndef _NO_DIRNAME
3 /* Copyright 2005 Shaun Jackman
4 * Permission to use, copy, modify, and distribute this software
5 * is freely granted, provided that this notice is preserved.
6 */
8 #include <libgen.h>
9 #include <string.h>
11 char *
12 dirname (char *path)
14 char *p;
15 if( path == NULL || *path == '\0' )
16 return ".";
17 p = path + strlen(path) - 1;
18 while( *p == '/' ) {
19 if( p == path )
20 return path;
21 *p-- = '\0';
23 while( p >= path && *p != '/' )
24 p--;
25 return
26 p < path ? "." :
27 p == path ? "/" :
28 (*p = '\0', path);
31 #endif /* !_NO_DIRNAME */