'\"macro stdmacro
.if n .pH g3g.dirname @(#)dirname	40.9 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} dirname 3G "" "\&"
.if \nX=1 .ds x} dirname 3G ""
.if \nX=2 .ds x} dirname 3G "" "\&"
.if \nX=3 .ds x} dirname "" "" "\&"
.TH \*(x}
.SH "NAME"
\f4dirname\f1 \- report the parent directory name of a file path name
.SH SYNOPSIS
\f4cc\f1
[\f2flag\fP \|.\|.\|.] \f2file\fP \|.\|.\|.
\f4\-lgen\f1
[\f2library\fP \|.\|.\|.]
.PP
\f4#include <libgen.h>\f1
.PP
\f4char \(**dirname (char \(**path);\f1
.SH DESCRIPTION
Given a pointer to a null-terminated character string that contains
a file system path name,
\f4dirname\fP
returns a pointer to a static constant string that is the parent directory of that file.
In doing this, it sometimes
places a null byte in the path name after the next to last element,
so the content of
.I path
must be disposable.
Trailing ``\f4/\fP'' characters in the path are not counted as part of the path.
.PP
If
.I path
or
.I \(**path
is zero, a pointer to a static constant ``\f4.\fP'' is returned.
.P
\f4dirname\fP
and
\f4basename\fP
together yield a complete path name.
\f4dirname (\f2path\fP)\f1
is the directory where
\f4basename (\f2path\fP)\f1
is found.
.SH EXAMPLES
A simple file name and the strings ``\f4.\fP'' and ``\f4..\fP'' all have ``\f4.\fP''
as their return value.
.TS
center ;
c c
lf4 lf4 .
Input string	Output pointer
_
/usr/lib	/usr
/usr/	/
usr	\&.
/	/
\&.	\&.
\&..	\&.
.TE
.PP
The following code reads a path name,
changes directory to the appropriate directory
[see \f4chdir\fP(2)],
and opens the file.
.PP
.RS
.ft 4
.nf
char path[100], \(**pathcopy;
int fd;
gets (path);
pathcopy = strdup (path);
chdir (dirname (pathcopy) );
fd = open (basename (path), O_RDONLY);
.fi
.ft 1
.RE
.SH "SEE ALSO"
\f4chdir\fP(2), \f4basename\fP(3G).
.br
\f4basename\fP(1) in the \f2User's Reference Manual\fP.
