1mkdirp(3GEN) String Pattern-Matching Library Functions mkdirp(3GEN)
2
3
4
6 mkdirp, rmdirp - create or remove directories in a path
7
9 cc [ flag ... ] file ... -lgen [ library ... ]
10 #include <libgen.h>
11
12 int mkdirp(const char *path, mode_t mode);
13
14
15 int rmdirp(char *dir, char *dir1);
16
17
19 The mkdirp() function creates all the missing directories in path with
20 mode. See chmod(2) for the values of mode.
21
22
23 The rmdirp() function removes directories in path dir. This removal
24 begins at the end of the path and moves backward toward the root as far
25 as possible. If an error occurs, the remaining path is stored in dir1.
26
28 If path already exists or if a needed directory cannot be created,
29 mkdirp() returns −1 and sets errno to one of the error values listed
30 for mkdir(2). It returns zero if all the directories are created.
31
32
33 The rmdirp() function returns 0 if it is able to remove every directory
34 in the path. It returns −2 if a ``.'' or ``..'' is in the path and −3
35 if an attempt is made to remove the current directory. Otherwise it
36 returns −1.
37
39 Example 1 Example of creating scratch directories.
40
41
42 The following example creates scratch directories.
43
44
45 /* create scratch directories */
46 if(mkdirp("/tmp/sub1/sub2/sub3", 0755) == −1) {
47 fprintf(stderr, "cannot create directory");
48 exit(1);
49 }
50 chdir("/tmp/sub1/sub2/sub3");
51 .
52 .
53 .
54 /* cleanup */
55 chdir("/tmp");
56 rmdirp("sub1/sub2/sub3");
57
58
60 See attributes(5) for descriptions of the following attributes:
61
62
63
64
65 ┌─────────────────────────────┬─────────────────────────────┐
66 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
67 ├─────────────────────────────┼─────────────────────────────┤
68 │MT-Level │MT-Safe │
69 └─────────────────────────────┴─────────────────────────────┘
70
72 chmod(2), mkdir(2), rmdir(2), malloc(3C), attributes(5)
73
75 The mkdirp() function uses malloc(3C) to allocate temporary space for
76 the string.
77
78
79
80SunOS 5.11 14 Oct 2003 mkdirp(3GEN)