#include <sys/stat.h> int fchmod(int fildes, mode_t mode);Service Program Name: QP0LLIB1
The fchmod() function changes S_ISUID, S_ISGID, S_ISVTX, and the permission bits of the open file or directory, identified by fildes, to the corresponding bits specified in mode. fchmod() has no effect on file descriptions for files that are open at the time fchmod() is called.
fchmod() marks for update the change time of the file.
If the file is checked out by another user (someone other than the user profile of the current job), fchmod() fails with the [EBUSY] error.
The mode argument is created with one of the symbols defined in the <sys/stat.h> header file. For more information on the symbols, refer to chmod()--Change File Authorizations.
If bits other than the bits listed above are set in mode, fchmod() returns the [EINVAL] error.
Authorization Required for fchmod() (excluding
QDLS)
Object Referred to | Authority Required | errno |
---|---|---|
Object | Owner (see Note) | EPERM |
Note: You do not need the listed authority if you have *ALLOBJ special authority. |
Authorization Required for fchmod() in the QDLS
File System
Object Referred to | Authority Required | errno |
---|---|---|
Object | Owner or *ALL | EACCES |
If fchmod() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
Error condition | Additional information |
---|---|
[EACCES] |
If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems. |
[EAGAIN] | |
[EBADF] | |
[EBADFID] | |
[EBADNAME] | |
[EBUSY] | |
[ECONVERT] | |
[EDAMAGE] | |
[EINTR] | |
[EINVAL] | |
[EIO] | |
[EJRNDAMAGE] | |
[EJRNENTTOOLONG] | |
[EJRNINACTIVE] | |
[EJRNRCVSPC] | |
[ENAMETOOLONG] | |
[ENEWJRN] | |
[ENEWJRNRCV] | |
[ENOENT] | |
[ENOSPC] | |
[ENOSYS] | |
[ENOSYSRSC] | |
[ENOTAVAIL] | |
[ENOTDIR] | |
[ENOTSAFE] | |
[ENOTSUP] | |
[EPERM] | |
[EROOBJ] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[EUNKNOWN] |
If interaction with a file server is required to access the object, errno could indicate one of the following errors:
Error condition | Additional information |
---|---|
[EADDRNOTAVAIL] | |
[ECONNABORTED] | |
[ECONNREFUSED] | |
[ECONNRESET] | |
[EHOSTDOWN] | |
[EHOSTUNREACH] | |
[ENETDOWN] | |
[ENETRESET] | |
[ENETUNREACH] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[ETIMEDOUT] | |
[EUNATCH] |
The following messages may be sent from this API:
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPFA0D4 E | File system error occurred. Error number &1. |
CPF3CF2 E | Error(s) occurred during running of &1 API. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
See Code disclaimer information for information pertaining to code examples.
The following example changes a file permission:
#include <stdio.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> main() { char fn[]="temp.file"; int file_descriptor; struct stat info; if ((file_descriptor = creat(fn, S_IWUSR)) < 0) perror("creat() error"); else { if (stat(fn, &info)!= 0) perror("stat() error"); else { printf("original permissions were: %08o\n", info.st_mode); } if (fchmod(file_descriptor, S_IRWXU|S_IRWXG) != 0) perror("fchmod() error"); else { if (stat(fn, &info)!= 0) perror("stat() error"); else { printf("after fchmod(), permissions are: %08o\n", info.st_mode); } } if (close(file_descriptor)!= 0) perror("close() error"); if (unlink(fn)!= 0) perror("unlink() error"); } }
Output:
original permissions were: 00100200 after fchmod(), permissions are: 00100770
Top | UNIX-Type APIs | APIs by category |