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
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   privilege   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
43       The fchown() function may fail if:
44
45       EINVAL The  owner or group ID is not a value supported by the implemen‐
46              tation.  The fildes argument refers to a pipe or socket   or  an
47              fattach()-ed  STREAM  and the implementation disallows execution
48              of fchown() on a pipe.
49
50       EIO    A physical I/O error has occurred.
51
52       EINTR  The fchown() function was interrupted  by  a  signal  which  was
53              caught.
54
55
56       The following sections are informative.
57

EXAMPLES

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

APPLICATION USAGE

87       None.
88

RATIONALE

90       None.
91

FUTURE DIRECTIONS

93       None.
94

SEE ALSO

96       chown(),  the  Base   Definitions   volume   of   IEEE Std 1003.1-2001,
97       <unistd.h>
98
100       Portions  of  this text are reprinted and reproduced in electronic form
101       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
102       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
103       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
104       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
105       event of any discrepancy between this version and the original IEEE and
106       The  Open Group Standard, the original IEEE and The Open Group Standard
107       is the referee document. The original Standard can be  obtained  online
108       at http://www.opengroup.org/unix/online.html .
109
110
111
112IEEE/The Open Group                  2003                           FCHOWN(3P)
Impressum