[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
#include <unistd.h> char * dirname (const char *fname); |
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.
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.
ANSI/ISO C | No |
POSIX | No |
printf ("The parent of current directory is %s\n", dirname (getcwd (0, PATH_MAX))); |