1FCHMOD(P)                  POSIX Programmer's Manual                 FCHMOD(P)
2
3
4

NAME

6       fchmod - change mode of a file
7

SYNOPSIS

9       #include <sys/stat.h>
10
11       int fchmod(int fildes, mode_t mode);
12
13

DESCRIPTION

15       The  fchmod()  function  shall be equivalent to chmod() except that the
16       file whose permissions are changed is specified by the file  descriptor
17       fildes.
18
19       If fildes references a shared memory object, the fchmod() function need
20       only affect  the  S_IRUSR,  S_IWUSR,  S_IRGRP,  S_IWGRP,  S_IROTH,  and
21       S_IWOTH file permission bits.
22
23       If fildes references a typed memory object, the behavior of fchmod() is
24       unspecified.
25
26       If fildes refers to a socket, the behavior of fchmod() is unspecified.
27
28       If fildes refers to a STREAM (which is fattach()-ed into the file  sys‐
29       tem name space) the call returns successfully, doing nothing.
30

RETURN VALUE

32       Upon  successful  completion,  fchmod()  shall  return 0. Otherwise, it
33       shall return -1 and set errno to indicate the error.
34

ERRORS

36       The fchmod() function shall fail if:
37
38       EBADF  The fildes argument is not an open file descriptor.
39
40       EPERM  The effective user ID does not match the owner of the  file  and
41              the process does not have appropriate privilege.
42
43       EROFS  The  file referred to by fildes resides on a read-only file sys‐
44              tem.
45
46
47       The fchmod() function may fail if:
48
49       EINTR  The fchmod() function was interrupted by a signal.
50
51       EINVAL The value of the mode argument is invalid.
52
53       EINVAL The fildes argument refers to a pipe and the implementation dis‐
54              allows execution of fchmod() on a pipe.
55
56
57       The following sections are informative.
58

EXAMPLES

60   Changing the Current Permissions for a File
61       The  following  example  shows how to change the permissions for a file
62       named /home/cnd/mod1 so that the owner and group  have  read/write/exe‐
63       cute permissions, but the world only has read/write permissions.
64
65
66              #include <sys/stat.h>
67              #include <fcntl.h>
68
69
70              mode_t mode;
71              int    fildes;
72              ...
73              fildes = open("/home/cnd/mod1", O_RDWR);
74              fchmod(fildes, S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH);
75

APPLICATION USAGE

77       None.
78

RATIONALE

80       None.
81

FUTURE DIRECTIONS

83       None.
84

SEE ALSO

86       chmod() , chown() , creat() , fcntl() , fstatvfs() , mknod() , open() ,
87       read()  ,  stat()  ,  write()  ,  the  Base   Definitions   volume   of
88       IEEE Std 1003.1-2001, <sys/stat.h>
89
91       Portions  of  this text are reprinted and reproduced in electronic form
92       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
93       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
94       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
95       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
96       event of any discrepancy between this version and the original IEEE and
97       The  Open Group Standard, the original IEEE and The Open Group Standard
98       is the referee document. The original Standard can be  obtained  online
99       at http://www.opengroup.org/unix/online.html .
100
101
102
103IEEE/The Open Group                  2003                            FCHMOD(P)
Impressum