dirname

Returns the parent component of a path name.

Library:LibC
Classification:Single UNIX
Service:File and Directory I/O

Syntax

  #include <libgen.h> 
   
  char *dirname (
     char   *path);
  

Parameters

path

(IN) Points to the buffer containing the path name.

Return Values

Returns a pointer to the parent component in the path:

  • If the path is a "/" or "\\" string, returns a pointer to the string: "/"

  • If the path is a NULL pointer or an empty string, returns a pointer to the string: "."

No errors have been defined for this function.

Remarks

The dirname function takes a pointer to a character string that contains a pathname, and returns a pointer to a string that is a path name of the parent directory of that file.

IMPORTANT:The dirname function is not thread-safe.

See Also