MKDIRP(3GEN) String Pattern-Matching Library Functions MKDIRP(3GEN)
mkdirp, rmdirp - create or remove directories in a path
cc [ flag ... ] file ... -lgen [ library ... ]
#include <libgen.h>
int mkdirp(const char *path, mode_t mode);
int rmdirp(char *dir, char *dir1);
The mkdirp() function creates all the missing directories in path
with mode. See chmod(2) for the values of mode.
The rmdirp() function removes directories in path dir. This removal
begins at the end of the path and moves backward toward the root as
far as possible. If an error occurs, the remaining path is stored in
dir1.
If path already exists or if a needed directory cannot be created,
mkdirp() returns -1 and sets errno to one of the error values listed
for mkdir(2). It returns zero if all the directories are created.
The rmdirp() function returns 0 if it is able to remove every
directory in the path. It returns -2 if a ``.'' or ``..'' is in the
path and -3 if an attempt is made to remove the current directory.
Otherwise it returns -1.
The following example creates scratch directories.
/* 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");
See attributes(7) for descriptions of the following attributes:
+---------------+-----------------+
|ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+---------------+-----------------+
|MT-Level | MT-Safe |
+---------------+-----------------+
chmod(2), mkdir(2), rmdir(2), malloc(3C), attributes(7)
The mkdirp() function uses malloc(3C) to allocate temporary space for
the string.
October 14, 2003 MKDIRP(3GEN)
NAME
mkdirp, rmdirp - create or remove directories in a path
SYNOPSIS
cc [ flag ... ] file ... -lgen [ library ... ]
#include <libgen.h>
int mkdirp(const char *path, mode_t mode);
int rmdirp(char *dir, char *dir1);
DESCRIPTION
The mkdirp() function creates all the missing directories in path
with mode. See chmod(2) for the values of mode.
The rmdirp() function removes directories in path dir. This removal
begins at the end of the path and moves backward toward the root as
far as possible. If an error occurs, the remaining path is stored in
dir1.
RETURN VALUES
If path already exists or if a needed directory cannot be created,
mkdirp() returns -1 and sets errno to one of the error values listed
for mkdir(2). It returns zero if all the directories are created.
The rmdirp() function returns 0 if it is able to remove every
directory in the path. It returns -2 if a ``.'' or ``..'' is in the
path and -3 if an attempt is made to remove the current directory.
Otherwise it returns -1.
EXAMPLES
Example 1: Example of creating scratch directories.
The following example creates scratch directories.
/* 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");
ATTRIBUTES
See attributes(7) for descriptions of the following attributes:
+---------------+-----------------+
|ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+---------------+-----------------+
|MT-Level | MT-Safe |
+---------------+-----------------+
SEE ALSO
chmod(2), mkdir(2), rmdir(2), malloc(3C), attributes(7)
NOTES
The mkdirp() function uses malloc(3C) to allocate temporary space for
the string.
October 14, 2003 MKDIRP(3GEN)