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
11

NAME

13       fchown — change owner and group of a file
14

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

57   Changing the Current Owner of a File
58       The  following  example  shows  how to change the owner of a file named
59       /home/cnd/mod1 to ``jones'' and the group to ``cnd''.
60
61       The numeric value for the user ID is obtained by extracting the user ID
62       from  the user database entry associated with ``jones''. Similarly, the
63       numeric value for the group ID is obtained by extracting the  group  ID
64       from  the  group  database  entry associated with ``cnd''. This example
65       assumes the calling program has appropriate privileges.
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‐2008, <unistd.h>
95
97       Portions of this text are reprinted and reproduced in  electronic  form
98       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
99       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
100       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
101       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
102       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
103       event of any discrepancy between this version and the original IEEE and
104       The  Open Group Standard, the original IEEE and The Open Group Standard
105       is the referee document. The original Standard can be  obtained  online
106       at http://www.unix.org/online.html .
107
108       Any  typographical  or  formatting  errors that appear in this page are
109       most likely to have been introduced during the conversion of the source
110       files  to  man page format. To report such errors, see https://www.ker
111       nel.org/doc/man-pages/reporting_bugs.html .
112
113
114
115IEEE/The Open Group                  2013                           FCHOWN(3P)
Impressum