2017-04-11 21:13:36 +00:00
|
|
|
#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 *
|
2018-12-28 15:30:48 +00:00
|
|
|
dirname (char *path)
|
2017-04-11 21:13:36 +00:00
|
|
|
{
|
|
|
|
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 */
|