chmod

Changes the file permissions of the specified file.

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

Syntax

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

Parameters

path

(IN) Specifies the file.

mode

(IN) Specifies the permission mode for the file, or on NetWare file systems, file and directory attributes (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 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.

9

EINVAL

The value of the mode argument is invalid.

63

EINTR

A signal was caught during execution of the function.

65

ENAMETOOLONG

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

67

ENOTDIR

A component of the path is not a directory.

69

EPERM

The caller does not have appropriate privileges.

76

EROFS

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

Remarks

The various mode settings are defined in the sys/mode.h header file and are described in File Access Modes and NetWare Attributes.

On NetWare file systems, you can use chmod to set file and directory attributes. If the M_A_BITS_SIGNIFICANT is set in the mode parameter, it means that the mode is being used to set the file and directory attributes. This functionality is mutually-exclusive of the normal chmod functionality:

  • If the M_A_BITS_SIGNIFICANT bit is set, only the NetWare-specific attribute bits are used and the user, group, and other flags are ignored.

  • If it is not set, the NetWare-specific flags are not examined.

See Also