FCHOWN(3)                  POSIX Programmer's Manual                 FCHOWN(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       fchown -- change owner and group of a file

SSYYNNOOPPSSIISS
       #include <unistd.h>

       int fchown(int _f_i_l_d_e_s, uid_t _o_w_n_e_r, gid_t _g_r_o_u_p);

DDEESSCCRRIIPPTTIIOONN
       The _f_c_h_o_w_n() function shall be equivalent to _c_h_o_w_n() except that the
       file whose owner and group are changed is specified by the file
       descriptor _f_i_l_d_e_s.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _f_c_h_o_w_n() shall return 0. Otherwise, it
       shall return -1 and set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       The _f_c_h_o_w_n() function shall fail if:

       EEBBAADDFF  The _f_i_l_d_e_s argument is not an open file descriptor.

       EEPPEERRMM  The effective user ID does not match the owner of the file or
              the process does not have appropriate privileges and
              _POSIX_CHOWN_RESTRICTED indicates that such privilege is
              required.

       EERROOFFSS  The file referred to by _f_i_l_d_e_s resides on a read-only file
              system.

       The _f_c_h_o_w_n() function may fail if:

       EEIINNVVAALL The owner or group ID is not a value supported by the
              implementation.  The _f_i_l_d_e_s argument refers to a pipe or socket
              or an _f_a_t_t_a_c_h()-ed STREAM and the implementation disallows
              execution of _f_c_h_o_w_n() on a pipe.

       EEIIOO    A physical I/O error has occurred.

       EEIINNTTRR  The _f_c_h_o_w_n() function was interrupted by a signal which was
              caught.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   CChhaannggiinngg tthhee CCuurrrreenntt OOwwnneerr ooff aa FFiillee
       The following example shows how to change the owner of a file named
       //hhoommee//ccnndd//mmoodd11 to ``jones'' and the group to ``cnd''.

       The numeric value for the user ID is obtained by extracting the user ID
       from the user database entry associated with ``jones''. Similarly, the
       numeric value for the group ID is obtained by extracting the group ID
       from the group database entry associated with ``cnd''. This example
       assumes the calling program has appropriate privileges.

           ##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
           ##iinncclluuddee <<uunniissttdd..hh>>
           ##iinncclluuddee <<ffccnnttll..hh>>
           ##iinncclluuddee <<ppwwdd..hh>>
           ##iinncclluuddee <<ggrrpp..hh>>

           struct passwd *pwd;
           struct group  *grp;
           int            fildes;
           ...
           fildes = open("/home/cnd/mod1", O_RDWR);
           pwd = getpwnam("jones");
           grp = getgrnam("cnd");
           fchown(fildes, pwd->pw_uid, grp->gr_gid);

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _c_h_o_w_n()

       The Base Definitions volume of POSIX.1-2008, <<uunniissttdd..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                            FCHOWN(3)
