mknod

Creates a directory, a file, or a FIFO.

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

Syntax

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

Parameters

path

(IN) Points to the path for the file.

mode

(IN) Specifies the type of object to create and must be set to one of the following:

Constant

Value

Description

S_IFIFO

0x1000

Specifies that the entry is a first-in/first-out device, either a FIFO or a pipe.

S_IFDIR

0x4000

Specifies that the entry is a directory.

S_IFREG

0x8000

Specifies that the entry is a regular file.

A permission's flag can be OR'd to one of the flags above. For a list of possible values, see File Access Modes and NetWare Attributes.

dev

(IN) Specifies the device type and must be set to 0.

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 path does not name an existing file or pathname is an empty string.

6

EACCES

Search permission is denied on a component of the path.

7

EEXIST

The directory already exists.

9

EINVAL

The value of the dev parameter is invalid.

65

ENAMETOOLONG

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

79

ENOTSUP

The value of the mode parameter is invalid.

105

ENOCONTEXT

The calling thread has no context.

See Also