[Previous]
[Contents]
[Next]

mkdir()

create a subdirectory

Synopsis:

#include <sys/types.h>
#include <sys/stat.h>
int mkdir( const char *path, mode_t mode );

Description:

The mkdir() function creates a new subdirectory with name path. The path can be either relative to the current working directory, or it can be an absolute path name.

The file permission bits of the new directory are initialized from mode. The file permission bits of the mode argument are modified by the process's file creation mask (see umask()). The access permissions for the file or directory are specified as a combination of bits. These are defined in the <sys/stat.h> header file, and described in the section on this file in the Header Files chapter.

The directory's owner ID is set to the process's effective user ID. The directory's group ID is set to the group ID of the directory in which the directory is being created or to the process's effective group ID.

The newly created directory will be empty.

Upon successful completion, the mkdir() function will mark for update the st_atime, st_ctime, and st_mtime fields of the directory. Also, the st_ctime and st_mtime fields of the directory that contains the new entry are marked for update.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EACCES
Search permission is denied for a component of path, or write permission is denied on the parent directory of the directory to be created.
EEXIST
The named file exists.
EMLINK
The link count of the parent directory would exceed LINK_MAX.
ENAMETOOLONG
The argument path exceeds PATH_MAX in length, or a pathname component is longer than NAME_MAX.
ENOENT
The specified path does not exist, 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.
ENOSYS
This function is not supported for this path.
ENOTDIR
A component of path is not a directory.
EROFS
The parent directory of the directory being created resides on a read-only file system.

Examples:

To make a new directory called /watcom on node 2:

#include <sys/types.h>
#include <sys/stat.h>

void main()
  {
    mkdir( "//2/hd/watcom",
           S_IRWXU |
           S_IRGRP | S_IXGRP |
           S_IROTH | S_IXOTH );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

chdir(), chmod(), errno, getcwd(), mknod(), rmdir(), stat(), umask()


[Previous]
[Contents]
[Next]