1mkdir(2)                         System Calls                         mkdir(2)
2
3
4

NAME

6       mkdir - make a directory
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/stat.h>
11
12       int mkdir(const char *path, mode_t mode);
13
14

DESCRIPTION

16       The  mkdir()  function  creates a  new directory named by the path name
17       pointed to by path. The mode of the new directory is  initialized  from
18       mode (see chmod(2) for values of mode). The protection part of the mode
19       argument  is  modified  by  the  process's  file  creation  mask   (see
20       umask(2)).
21
22
23       The  directory's  owner  ID is set to  the process's effective user ID.
24       The directory's group ID is set to the  process's effective  group  ID,
25       or if the S_ISGID bit is set in the parent directory, then the group ID
26       of the directory is inherited from the parent.  The S_ISGID bit of  the
27       new directory is  inherited from the parent directory.
28
29
30       If path names a symbolic link, mkdir() fails and sets errno to EEXIST.
31
32
33       The  newly created directory is empty with the exception of entries for
34       itself (.) and its parent directory (..).
35
36
37       Upon successful completion, mkdir()  marks  for  update  the  st_atime,
38       st_ctime  and  st_mtime fields of the directory. Also, the st_ctime and
39       st_mtime fields of the directory that contains the new entry are marked
40       for update.
41

RETURN VALUES

43       Upon  successful  completion, 0 is returned. Otherwise, −1 is returned,
44       no directory is created, and  errno is set to indicate the error.
45

ERRORS

47       The mkdir() function will fail if:
48
49       EACCES          Either a component of the  path  prefix  denies  search
50                       permission  or write permission is denied on the parent
51                       directory of the directory to be created.
52
53
54       EDQUOT          The directory where the new file entry is being  placed
55                       cannot  be  extended  because  the user's quota of disk
56                       blocks on that file system has been exhausted; the  new
57                       directory cannot be created because the user's quota of
58                       disk blocks on that file system has been exhausted;  or
59                       the user's quota of inodes on the file system where the
60                       file is being created has been exhausted.
61
62
63       EEXIST          The named file already exists.
64
65
66       EFAULT          The path argument points to an illegal address.
67
68
69       EINVAL          An attempt was made to  create  an  extended  attribute
70                       that is a directory.
71
72
73       EIO             An I/O error has occurred while accessing the file sys‐
74                       tem.
75
76
77       EILSEQ          The path argument includes non-UTF8 characters and  the
78                       file  system  accepts only file names where all charac‐
79                       ters are part of the UTF-8 character codeset.
80
81
82       ELOOP           Too many symbolic links were encountered in translating
83                       path,  or  a  loop exists in symbolic links encountered
84                       during resolution of path
85
86
87       EMLINK          The maximum number of links  to  the  parent  directory
88                       would be exceeded.
89
90
91       ENAMETOOLONG    The  length  of  the path argument exceeds PATH_MAX, or
92                       the length of a path component exceeds  NAME_MAX  while
93                       _POSIX_NO_TRUNC is in effect.
94
95
96       ENOENT          A  component  of the path prefix does not exist or is a
97                       null pathname.
98
99
100       ENOLINK         The path argument points to a remote  machine  and  the
101                       link to that machine is no longer active.
102
103
104       ENOSPC          No free space is available on the device containing the
105                       directory.
106
107
108       ENOTDIR         A component of the path prefix is not a directory.
109
110
111       EROFS           The path prefix resides on a read-only file system.
112
113
114
115       The mkdir() function may fail if:
116
117       ENAMETOOLONG    As a result of encountering a symbolic link in  resolu‐
118                       tion  of  the  path argument, the length of the substi‐
119                       tuted pathname string exceeded {PATH_MAX}.
120
121

EXAMPLES

123       Example 1 Create a directory.
124
125
126       The following example demonstrates how  to  create  a  directory  named
127       /home/cnd/mod1,  with read, write, and search permissions for owner and
128       group, and with read and search permissions for others.
129
130
131         #include <sys/types.h>
132         #include <sys/stat.h>
133         int status;
134         ...
135         status = mkdir("/home/cnd/mod1",
136              S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
137
138

ATTRIBUTES

140       See attributes(5) for descriptions of the following attributes:
141
142
143
144
145       ┌─────────────────────────────┬─────────────────────────────┐
146       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
147       ├─────────────────────────────┼─────────────────────────────┤
148       │Interface Stability          │Standard                     │
149       ├─────────────────────────────┼─────────────────────────────┤
150       │MT-Level                     │Async-Signal-Safe            │
151       └─────────────────────────────┴─────────────────────────────┘
152

SEE ALSO

154       chmod(2),    mknod(2),    umask(2),    mkdirp(3GEN),     stat.h(3HEAD),
155       attributes(5), standards(5)
156
157
158
159SunOS 5.11                        18 May 2007                         mkdir(2)
Impressum