delorie.com/djgpp/doc/libc/libc_132.html
|
search
|
libc.a reference
dirname
Syntax
| #include <unistd.h>
char * dirname (const char *fname);
|
Description
This function returns the directory part of the argument fname
copied to a buffer allocated by calling malloc
. The directory
part is everything up to but not including the rightmost slash (either
forward- or backslash) in fname. If fname includes a drive
letter but no slashes, the function will return x:.
where
x is the drive letter. If fname includes neither the drive
letter nor any slashes, "."
will be returned. Trailing slashes
are removed from the result, unless it is a root directory, with or
without a drive letter.
Return value
The directory part in malloc'ed storage, or a NULL pointer of either
there's not enough free memory, or fname is a NULL pointer.
Portability
Example
| printf ("The parent of current directory is %s\n",
dirname (getcwd (0, PATH_MAX)));
|