Directory/RB_Get_PathName [ Functions ]
NAME
RB_Get_PathName -- extract the path name
SYNOPSIS
char *RB_Get_PathName( char *arg_fullpath )
FUNCTION
Given a full path to a file, that is a filename, or a filename prefixed with a pathname, return the pathname. So
"./filename" returns "./" "/home/et/filename" returns "/home/et/" "filename" return ""
INPUTS
arg_fullpath -- a full path to a file, with or without a path.
RESULT
0 -- The full path did not contain a path pointer to the pathname -- otherwise.
NOTES
You are responsible for deallocating it.
SOURCE
{ int n; int i; int found; char *result = 0; assert( arg_fullpath ); n = strlen( arg_fullpath ); /* Try and find a path character ( ':' or '/' ) */ for ( found = FALSE, i = 0; i < n; ++i ) { if ( RB_Is_PathCharacter( arg_fullpath[i] ) ) { found = TRUE; break; } } if ( found ) { /* Copy the whole file name and then replace the character after the first path character found counting from the back with a '\0' */ result = RB_StrDup( arg_fullpath ); for ( i = n - 1; i > 0; --i ) { if ( RB_Is_PathCharacter( result[i] ) ) { assert( i < ( n - 1 ) ); result[i + 1] = '\0'; break; } } } return result; }