Newlib:
- Added missing basename.c; - Added original dirname.c; - Added getcwd (extension of POSIX.1 standard, as in the original NewLib). git-svn-id: svn://kolibrios.org@9989 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
32
contrib/sdk/sources/newlib/libc/unix/dirname.c
Normal file
32
contrib/sdk/sources/newlib/libc/unix/dirname.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef _NO_DIRNAME
|
||||
|
||||
/* 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 (dirname, (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 < path ? "." :
|
||||
p == path ? "/" :
|
||||
(*p = '\0', path);
|
||||
}
|
||||
|
||||
#endif /* !_NO_DIRNAME */
|
Reference in New Issue
Block a user