Last change
on this file since 444 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
559 bytes
|
Rev | Line | |
---|
[444] | 1 | #ifndef _NO_DIRNAME |
---|
| 2 | |
---|
| 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 | */ |
---|
| 7 | |
---|
| 8 | #include <libgen.h> |
---|
| 9 | #include <string.h> |
---|
| 10 | |
---|
| 11 | char * |
---|
| 12 | dirname (char *path) |
---|
| 13 | { |
---|
| 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'; |
---|
| 22 | } |
---|
| 23 | while( p >= path && *p != '/' ) |
---|
| 24 | p--; |
---|
| 25 | return |
---|
| 26 | p < path ? "." : |
---|
| 27 | p == path ? "/" : |
---|
| 28 | (*p = '\0', path); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | #endif /* !_NO_DIRNAME */ |
---|
Note: See
TracBrowser
for help on using the repository browser.