<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="com" style="color: rgb(136, 0, 0);">/* Change the owner and group of FILE. */</span><span class="pln"> </span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">extern</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> chown </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">__const </span><span class="kwd" style="color: rgb(0, 0, 136);">char</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">__file</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">__uid_t</span><span class="pln"> __owner</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">__gid_t</span><span class="pln"> __group</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln">__THROW __nonnull </span><span class="pun" style="color: rgb(102, 102, 0);">((</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">))</span><span class="pln"> __wur</span><span class="pun" style="color: rgb(102, 102, 0);">;</span><span class="pln"> </span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>此函数的第一个参数为欲修改用户的文件,第二个参数为修改后的文件拥有者,第三个参数为修改后该文件拥有者所在的组。
对于已打开的文件,使用 fchown 函数来修改。其第一个参数为已打开文件的文件描述符,其他同 chown 函数。该函数声明如下:
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="com" style="color: rgb(136, 0, 0);">/* Change the owner and group of the file that FD is open on. */</span><span class="pln"> </span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">extern</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> fchown </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> __fd</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">__uid_t</span><span class="pln"> __owner</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">__gid_t</span><span class="pln"> __group</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> __THROW __wur</span><span class="pun" style="color: rgb(102, 102, 0);">;</span><span class="pln"> </span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>对于连接文件,则可以使用 lchown 函数。其参数同于 chown 函数。
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="com" style="color: rgb(136, 0, 0);">/* Change owner and group of FILE, if it is a symbolic link the ownership of the symbolic </span></div><div><span class="com" style="color: rgb(136, 0, 0);">link is changed. */</span><span class="pln"> </span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">extern</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> lchown </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">__const </span><span class="kwd" style="color: rgb(0, 0, 136);">char</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">__file</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">__uid_t</span><span class="pln"> __owner</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">__gid_t</span><span class="pln"> __group</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> __THROW __nonnull </span><span class="pun" style="color: rgb(102, 102, 0);">((</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">))</span><span class="pln"> __wur</span><span class="pun" style="color: rgb(102, 102, 0);">;</span><span class="pln"> </span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>以上这 3 个函数如果执行成功,将返回 0,否则返回-1。