mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-15 19:09:58 +08:00
fd450adfe7
* libc/unix/basename.c: Add !_NO_BASENAME flag check so code can be ignored if desired by a platform. * libc/unix/dirname.c: Ditto except replace BASENAME with file name. * libc/unix/getcwd.c: Ditto. * libc/unix/getlogin.c: Ditto. * libc/unix/getpass.c: Ditto. * libc/unix/getpwent.c: Ditto. * libc/unix/getut.c: Ditto. * libc/unix/pread.c: Ditto. * libc/unix/pwrite.c: Ditto. * libc/unix/sigset.c: Ditto.
29 lines
525 B
C
29 lines
525 B
C
#ifndef _NO_BASENAME
|
|
/* Copyright 2005 Shaun Jackman
|
|
* Permission to use, copy, modify, and distribute this software
|
|
* is freely granted, provided that this notice is preserved.
|
|
*/
|
|
|
|
#include <libgen.h>
|
|
#include <string.h>
|
|
|
|
char*
|
|
_DEFUN (basename, (path),
|
|
char *path)
|
|
{
|
|
char *p;
|
|
if( path == NULL || *path == '\0' )
|
|
return ".";
|
|
p = path + strlen(path) - 1;
|
|
while( *p == '/' ) {
|
|
if( p == path )
|
|
return path;
|
|
*p-- = '\0';
|
|
}
|
|
while( p >= path && *p != '/' )
|
|
p--;
|
|
return p + 1;
|
|
}
|
|
|
|
#endif /* !_NO_BASENAME */
|