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

NAME

6       fchown - change owner and group of a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       int fchown(int fildes, uid_t owner, gid_t group);
12
13

DESCRIPTION

15       The  fchown()  function  shall be equivalent to chown() except that the
16       file whose owner and  group  are  changed  is  specified  by  the  file
17       descriptor fildes.
18

RETURN VALUE

20       Upon  successful  completion,  fchown()  shall  return 0. Otherwise, it
21       shall return -1 and set errno to indicate the error.
22

ERRORS

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

EXAMPLES

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

APPLICATION USAGE

81       None.
82

RATIONALE

84       None.
85

FUTURE DIRECTIONS

87       None.
88

SEE ALSO

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