chmod(), fchmod()

set file permissions 

Function


SYNOPSIS

#include <sys/types.h>

#include <sys/stat.h>

int chmod(const char *pathname, mode_t mode);

int fchmod(int fildes, mode_t mode);


DESCRIPTION

The chmod() function sets the access permissions for the file whose name is given by pathname to the bit pattern contained in mode. For this call to succeed, the effective user ID of the process must match the owner of the file, or the process must have appropriate privileges. The owner of the file pathname always has privileges to change permission modes and file attributes.

The fchmod() function has the same effect as chmod() except that the file whose permissions are to be changed is specified by file descriptor rather than path name.

The bits in mode define access permissions for the user associated with the file, the group associated with the file, and all others. The value of mode is the bitwise inclusive-or of one of the access permissions to be checked.

When successfully completed, these functions mark the st_ctime field of the file for update.


PARAMETERS

pathname 

Points to the name of the file.

fildes 

Is the file descriptor of an open file.

mode 

Is a bitwise-or field that specifies the new permission modes for path name.


RETURN VALUES

If successful, chmod() and fchmod() return zero. On failure, they returns -1 and set errno to the corresponding value.

EACCES 

Search permission is denied on a component of pathname.

EBADF 

fildes is not a valid file descriptor.

EFAULT 

pathname points outside the allocated address space of the process.

EINTR 

A signal interrupted the call.

EIO 

An I/O error occurred while reading from or writing to the file system.

EINVAL 

The value of the mode argument is invalid.

ENAMETOOLONG 

The length of the pathname parameter exceeds PATH_MAX or a pathname component is longer than NAME_MAX while _POSIX_NO_TRUNC is in effect.

ENOENT 

The named file does not exist or the pathname parameter points to an empty string.

ENOTDIR 

A component of the pathname prefix is not a directory.

EPERM 

The effective user ID does not match the owner of the file and the calling process does not have the appropriate privileges.


CONFORMANCE

POSIX.1 (1996), with exceptions.


MULTITHREAD SAFETY LEVEL

chmod(): Async-signal-safe.

fchmod(): MT-Safe.


PORTING ISSUES

Windows file systems have a set of DOS attribute bits. One of these bits is for the read-only status of a file. On file systems other than NTFS, these functions set the read-only attribute bit if no write-enable bit is specified in mode. Otherwise, the read-only attribute bit is cleared. For NTFS, the read-only attribute bit is set if no write-enable bit is set in the Access Control List for the file, and cleared otherwise.

There are differences in how the NuTCRACKER Platform uses some of the bits in mode, compared to the referenced standard. Refer to the struct stat page, to File Management in the Windows Concepts chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide, and also Security in the API-Specific Porting Issues chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
chown(), creat(), fchown(), fcntl(), mkdir(), mkfifo(), open(), read(), stat(), write()

Miscellaneous:
struct stat


PTC MKS Toolkit 10.5 Documentation Build 40.