1FCHMOD(3P) POSIX Programmer's Manual FCHMOD(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 fchmod — change mode of a file
14
16 #include <sys/stat.h>
17
18 int fchmod(int fildes, mode_t mode);
19
21 The fchmod() function shall be equivalent to chmod() except that the
22 file whose permissions are changed is specified by the file descriptor
23 fildes.
24
25 If fildes references a shared memory object, the fchmod() function need
26 only affect the S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and
27 S_IWOTH file permission bits.
28
29 If fildes references a typed memory object, the behavior of fchmod() is
30 unspecified.
31
32 If fildes refers to a socket, the behavior of fchmod() is unspecified.
33
34 If fildes refers to a STREAM (which is fattach()-ed into the file sys‐
35 tem name space) the call returns successfully, doing nothing.
36
38 Upon successful completion, fchmod() shall return 0. Otherwise, it
39 shall return −1 and set errno to indicate the error.
40
42 The fchmod() function shall fail if:
43
44 EBADF The fildes argument is not an open file descriptor.
45
46 EPERM The effective user ID does not match the owner of the file and
47 the process does not have appropriate privileges.
48
49 EROFS The file referred to by fildes resides on a read-only file sys‐
50 tem.
51
52 The fchmod() function may fail if:
53
54 EINTR The fchmod() function was interrupted by a signal.
55
56 EINVAL The value of the mode argument is invalid.
57
58 EINVAL The fildes argument refers to a pipe and the implementation dis‐
59 allows execution of fchmod() on a pipe.
60
61 The following sections are informative.
62
64 Changing the Current Permissions for a File
65 The following example shows how to change the permissions for a file
66 named /home/cnd/mod1 so that the owner and group have read/write/exe‐
67 cute permissions, but the world only has read/write permissions.
68
69 #include <sys/stat.h>
70 #include <fcntl.h>
71
72 mode_t mode;
73 int fildes;
74 ...
75 fildes = open("/home/cnd/mod1", O_RDWR);
76 fchmod(fildes, S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH);
77
79 None.
80
82 None.
83
85 None.
86
88 chmod(), chown(), creat(), fcntl(), fstatat(), fstatvfs(), mknod(),
89 open(), read(), write()
90
91 The Base Definitions volume of POSIX.1‐2008, <sys_stat.h>
92
94 Portions of this text are reprinted and reproduced in electronic form
95 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
96 -- Portable Operating System Interface (POSIX), The Open Group Base
97 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
98 cal and Electronics Engineers, Inc and The Open Group. (This is
99 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
100 event of any discrepancy between this version and the original IEEE and
101 The Open Group Standard, the original IEEE and The Open Group Standard
102 is the referee document. The original Standard can be obtained online
103 at http://www.unix.org/online.html .
104
105 Any typographical or formatting errors that appear in this page are
106 most likely to have been introduced during the conversion of the source
107 files to man page format. To report such errors, see https://www.ker‐
108 nel.org/doc/man-pages/reporting_bugs.html .
109
110
111
112IEEE/The Open Group 2013 FCHMOD(3P)