cc [ flag ... ] file ... -lgen [ library ... ]
#include <libgen.h>
int mkdirp(const char *path, mode_t mode);
int rmdirp(char *dir, char *dir1);
MT-Safe
rmdirp() removes directories in path dir. 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 dir1. rmdirp() returns a 0 only if it is able to remove every directory in the path.
/* 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");
rmdirp() returns -2 if a ‘‘.’’ or ‘‘..’’ 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.
When compiling multi-thread applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in multi-thread applications.