mkdir
function can fail for many reasons:
[EACCES]
Search permission is denied on a component of the path prefix, or write permission is denied on the parent directory of the directory to be created.
[EEXIST]
The named file exists.
[ELOOP]
A loop exists in symbolic links encountered during resolution of the path argument.
[EMLINK]
The link count of the parent directory would exceed {LINK_MAX}.
[ENAMETOOLONG]
The length of the path argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.
[ENOENT]
A component of the path prefix specified by path does not name an existing directory or path is an empty string.
[ENOSPC]
The file system does not contain enough space to hold the contents of the new directory or to extend the parent directory of the new directory.
[ENOTDIR]
A component of the path prefix is not a directory.
[EROFS]
The parent directory resides on a read-only file system.
The mkdir() function may fail if:
[ELOOP]
More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path argument.
[ENAMETOOLONG]
As a result of encountering a symbolic link in resolution of the path argument, the length of the substituted pathname string exceeded {PATH_MAX}.
If the function returns -1
you can't be sure of which specific error without checking errno
, that's why it is suggested.