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

PROLOG

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

NAME

12       fchown — change owner and group of a file
13

SYNOPSIS

15       #include <unistd.h>
16
17       int fchown(int fildes, uid_t owner, gid_t group);
18

DESCRIPTION

20       The fchown() function shall be equivalent to chown()  except  that  the
21       file  whose  owner  and  group  are  changed  is  specified by the file
22       descriptor fildes.
23

RETURN VALUE

25       Upon successful completion, fchown()  shall  return  0.  Otherwise,  it
26       shall return -1 and set errno to indicate the error.
27

ERRORS

29       The fchown() function shall fail if:
30
31       EBADF  The fildes argument is not an open file descriptor.
32
33       EPERM  The  effective  user  ID does not match the owner of the file or
34              the  process  does   not   have   appropriate   privileges   and
35              _POSIX_CHOWN_RESTRICTED   indicates   that   such  privilege  is
36              required.
37
38       EROFS  The file referred to by fildes resides on a read-only file  sys‐
39              tem.
40
41       The fchown() function may fail if:
42
43       EINVAL The  owner or group ID is not a value supported by the implemen‐
44              tation.  The fildes argument refers to a pipe or  socket  or  an
45              fattach()-ed  STREAM  and the implementation disallows execution
46              of fchown() on a pipe.
47
48       EIO    A physical I/O error has occurred.
49
50       EINTR  The fchown() function was interrupted  by  a  signal  which  was
51              caught.
52
53       The following sections are informative.
54

EXAMPLES

56   Changing the Current Owner of a File
57       The  following  example  shows  how to change the owner of a file named
58       /home/cnd/mod1 to ``jones'' and the group to ``cnd''.
59
60       The numeric value for the user ID is obtained by extracting the user ID
61       from  the user database entry associated with ``jones''. Similarly, the
62       numeric value for the group ID is obtained by extracting the  group  ID
63       from  the  group  database  entry associated with ``cnd''. This example
64       assumes the calling program has appropriate privileges.
65
66
67           #include <sys/types.h>
68           #include <unistd.h>
69           #include <fcntl.h>
70           #include <pwd.h>
71           #include <grp.h>
72
73           struct passwd *pwd;
74           struct group  *grp;
75           int            fildes;
76           ...
77           fildes = open("/home/cnd/mod1", O_RDWR);
78           pwd = getpwnam("jones");
79           grp = getgrnam("cnd");
80           fchown(fildes, pwd->pw_uid, grp->gr_gid);
81

APPLICATION USAGE

83       None.
84

RATIONALE

86       None.
87

FUTURE DIRECTIONS

89       None.
90

SEE ALSO

92       chown()
93
94       The Base Definitions volume of POSIX.1‐2017, <unistd.h>
95
97       Portions of this text are reprinted and reproduced in  electronic  form
98       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
99       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
100       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
101       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
102       event of any discrepancy between this version and the original IEEE and
103       The Open Group Standard, the original IEEE and The Open Group  Standard
104       is  the  referee document. The original Standard can be obtained online
105       at http://www.opengroup.org/unix/online.html .
106
107       Any typographical or formatting errors that appear  in  this  page  are
108       most likely to have been introduced during the conversion of the source
109       files to man page format. To report such errors,  see  https://www.ker
110       nel.org/doc/man-pages/reporting_bugs.html .
111
112
113
114IEEE/The Open Group                  2017                           FCHOWN(3P)
Impressum