| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 2: System Calls Oracle Solaris 11 Information Library |
- make a directory relative to directory file descriptor
#include <sys/stat.h>intmkdir(const char *path,mode_tmode);
int mkdirat(intfd, const char *path, mode_tmode);
Themkdir() function creates a new directory named by the pathname pointed to bypath. The mode of the new directory is initialized frommode (seechmod(2) for values of mode). The protectionpart of themode argument is modified by the process's file creationmask (seeumask(2)).
The directory's owner ID is set to the process's effective userID. The directory's group ID is set to the process's effectivegroup ID, or if theS_ISGID bit is set in the parentdirectory, then the group ID of the directory is inherited from the parent. TheS_ISGID bit of the new directory is inherited fromthe parent directory.
Ifpath names a symbolic link,mkdir() fails and sets errno toEEXIST.
The newly created directory is empty with the exception of entries foritself (.) and its parent directory (..).
Upon successful completion,mkdir() marks for update thest_atime,st_ctime andst_mtimefields of the directory. Also, thest_ctime andst_mtime fields of thedirectory that contains the new entry are marked for update.
Themkdirat() function is equivalent to themkdir() function except in thecase wherepath specifies a relative path. In this case the newlycreated directory is created relative to the directory associated with the filedescriptorfd instead of the current working directory. If the file descriptorwas opened withoutO_SEARCH, the function checks whether directory searches are permittedusing the current permissions of the directory underlying the file descriptor. Ifthe file descriptor was opened withO_SEARCH, the function does not perform thecheck.
Ifmkdirat() is passed the special valueAT_FDCWD in thefd parameter,the current working directory is used and the behavior is identical toa call tomkdir().
Upon successful completion,0 is returned. Otherwise,-1 is returned, no directoryis created, anderrno is set to indicate the error.
Themkdir() andmkdirat() functions will fail if:
Either a component of the path prefix denies search permission or write permission is denied on the parent directory of the directory to be created.
The directory where the new file entry is being placed cannot be extended because the user's quota of disk blocks on that file system has been exhausted; the new directory cannot be created because the user's quota of disk blocks on that file system has been exhausted; or the user's quota of inodes on the file system where the file is being created has been exhausted.
The named file already exists.
Thepath argument points to an illegal address.
An attempt was made to create an extended attribute that is a directory.
An I/O error has occurred while accessing the file system.
The path argument includes non-UTF8 characters and the file system accepts only file names where all characters are part of the UTF-8 character codeset.
Too many symbolic links were encountered in translatingpath, or a loop exists in symbolic links encountered during resolution ofpath
The maximum number of links to the parent directory would be exceeded.
The length of thepath argument exceedsPATH_MAX, or the length of apath component exceedsNAME_MAX while_POSIX_NO_TRUNC is in effect.
A component of the path prefix does not exist or is a null pathname.
Thepath argument points to a remote machine and the link to that machine is no longer active.
No free space is available on the device containing the directory.
A component of the path prefix is not a directory.
The path prefix resides on a read-only file system.
Themkdirat() function will fail if:
Thepath argument does not specify an absolute path and thefd argument is neitherAT_FDCWD nor a valid file descriptor open for reading.
Themkdir() andmkdirat() functions may fail if:
More than {SYMLOOP_MAX} symbolic links were encountered during resolution of thepath argument.
As a result of encountering a symbolic link in resolution of thepath argument, the length of the substituted pathname string exceeded {PATH_MAX}.
Themkdirat() function may fail if:
Thepath argument is not an absolute path andfd is neitherAT_FDCWD nor a file descriptor associated with a directory.
Example 1 Create a directory.
The following example demonstrates how to create a directory named/home/cnd/mod1, withread, write, and search permissions for owner and group, and with readand search permissions for others.
#include <sys/stat.h>int status;...status = mkdir("/home/cnd/mod1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);Seeattributes(5) for descriptions of the following attributes:
|
chmod(2),mknod(2),umask(2),mkdirp(3GEN),stat.h(3HEAD),attributes(5),standards(5)
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |