'\"macro stdmacro
.if n .pH g3g.mkdirp @(#)mkdirp	40.9 of 10/27/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} mkdirp 3G "" "\&"
.if \nX=1 .ds x} mkdirp 3G ""
.if \nX=2 .ds x} mkdirp 3G "" "\&"
.if \nX=3 .ds x} mkdirp "" "" "\&"
.TH \*(x}
.SH "NAME"
\f4mkdirp\f1, \f4rmdirp\f1 \- create, remove directories in a path
.SH "SYNOPSIS"
\f4cc\f1
[\f2flag\fP \|.\|.\|.] \f2file\fP \|.\|.\|.
\f4\-lgen\f1
[\f2library\fP \|.\|.\|.]
.PP
\f4#include <libgen.h>\f1
.PP
\f4int mkdirp (const char \(**path, mode_t mode);\f1
.PP
\f4int rmdirp (char \(**d, char \(**d1);\f1
.SH DESCRIPTION
\f4mkdirp\fP creates all the missing directories in the given
\f2path\f1 with the given \f2mode\f1.  [See \f4chmod\fP(2) 
for the values of \f2mode.\f1]
.PP
\f4rmdirp\f1 removes directories in path \f2d\f1.  
This removal starts at the end of the path
and moves back toward the root as far as possible.
If an error occurs, the remaining path is stored
in \f2d1\f1.  \f4rmdirp\f1 returns a 0 only if it is 
able to remove every directory in the path.
.SH EXAMPLES
.sp 0.5
.ft 4
.nf
/\(** create scratch directories \(**/
if(mkdirp("/tmp/sub1/sub2/sub3", 0755) =\^= -1) {
	fprintf(stderr, "cannot create directory");
	exit(1);
}
chdir("/tmp/sub1/sub2/sub3");
\&\.
\&\.
\&\.
/\(** cleanup \(**/
chdir("/tmp");
rmdirp("sub1/sub2/sub3");
.fi
.ft 1
.SH "SEE ALSO"
\f4mkdir\fP(2), \f4rmdir\fP(2).
.SH DIAGNOSTICS
If a needed directory cannot be created,
\f4mkdirp\fP returns \-1 and sets \f4errno\f1
to one of the \f4mkdir\fP\f1 error
numbers.  If all the directories are 
created, or existed to begin with, it returns zero.
.SH NOTES
\f4mkdirp\fP uses \f4malloc\fP to allocate 
temporary space for the string.
.PP
\f4rmdirp\f1 returns \-2 if a ``\f4.\fP'' or ``\f4..\fP''
is in the path and \-3 if an 
attempt is made to remove the current directory.
If an error occurs other than one 
of the above, \-1 is returned.
