mkdir

Creates a new directory.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

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

Parameters

pathname

(IN) Points to the path for the new directory (either relative to the current working directory or an absolute pathname).

mode

(IN) Specifies the permission mode for the directory (see File Access Modes and NetWare Attributes).

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

1

ENOENT

A component of the path specified by pathname does not name an existing directory or pathname is an empty string. NetWare traditional file systems also return this error if the directory already exists. For an existing directory, NSS file systems return the more conventional error: EEXIST.

6

EACCES

Search permission is denied on a component of pathname, or write permission is denied on the parent directory of the directory to be created.

7

EEXIST

The directory to create already exists.

12

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.

65

ENAMETOOLONG

The length of the path argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.

67

ENOTDIR

A component of pathname is not a directory

72

EMLINK

The link count of the parent directory would exceed {LINK_MAX}.

76

EROFS

The named parent directory resides on a read-only file system.

Remarks

The newly created directory must be an empty directory.

On NetWare file systems, the caller must have Create rights in the parent directory. The inherited rights mask for the new directory is ALL rights. You can use the mode parameter to set NetWare directory attributes.

See Also