📄 chown.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>chown</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_001_449"> </a>NAME</h4><blockquote>chown - change owner and group of a file</blockquote><h4><a name = "tag_000_001_450"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="systypes.h.html">sys/types.h</a>>#include <<a href="unistd.h.html">unistd.h</a>>int chown(const char *<i>path</i>, uid_t <i>owner</i>, gid_t <i>group</i>);</code></pre></blockquote><h4><a name = "tag_000_001_451"> </a>DESCRIPTION</h4><blockquote>The<i>path</i>argument points to a pathname naming a file. The user ID and group IDof the named file are set to the numeric values contained in<i>owner</i>and<i>group</i>respectively.<p>On XSI-conformant systems {_POSIX_CHOWN_RESTRICTED} is alwaysdefined, therefore:<ul><p><li>Changing the user ID is restricted to processes with appropriateprivileges.<p><li>Changing the group ID is permitted to a process with an effective userID equal to the user ID of the file, but without appropriateprivileges, if and only if<i>owner</i>is equal to the file's user IDor (<b> uid_t</b> )-1and<i>group</i>is equal either to the calling process' effective group ID or toone of its supplementary group IDs.<p></ul><p>If the<i>path</i>argument refers to a regular file, the set-user-ID (S_ISUID) andset-group-ID (S_ISGID) bits of the file mode are clearedupon successful return from<i>chown()</i>,unless the call is made by a process with appropriate privileges,in which case it is implementation-dependent whether these bits arealtered.If<i>chown()</i>is successfully invoked on a file that is not a regularfile, these bits may be cleared.These bits are defined in<i><a href="sysstat.h.html"><sys/stat.h></a></i>.<p>If<i>owner</i>or<i>group</i>is specified as (<b>uid_t</b>)-1 or (<b>gid_t</b>)-1respectively, the corresponding ID of the file is unchanged.<p>Upon successful completion,<i>chown()</i>will mark for update the<i>st_ctime</i>field of the file.</blockquote><h4><a name = "tag_000_001_452"> </a>RETURN VALUE</h4><blockquote>Upon successful completion, 0 is returned.Otherwise, -1 is returned and<i>errno</i>is set to indicate the error.If -1 is returned, no changes are made in the user IDand group ID of the file.</blockquote><h4><a name = "tag_000_001_453"> </a>ERRORS</h4><blockquote>The<i>chown()</i>function will fail if:<dl compact><dt>[EACCES]<dd>Search permission is denied on a component of the path prefix.<dt>[ELOOP]<dd>Too many symbolic links were encountered in resolving <i>path</i>.<dt>[ENAMETOOLONG]<dd>The length of the<i>path</i>argument exceeds {PATH_MAX}or a pathname component is longer than {NAME_MAX}.<dt>[ENOTDIR]<dd>A component of the path prefix is not a directory.<dt>[ENOENT]<dd>A component of <i>path</i> does not name an existing fileor <i>path</i> is an empty string.<dt>[EPERM]<dd>The effective user IDdoes not match the owner of the file, or thecalling process does not have appropriate privileges.<dt>[EROFS]<dd>The named file resides on a read-only file system.</dl><p>The<i>chown()</i>function may fail if:<dl compact><dt>[EIO]<dd>An I/O error occurred while reading or writing to the file system.<dt>[EINTR]<dd>The<i>chown()</i>function was interrupted by a signal which was caught.<dt>[EINVAL]<dd>The owner or group IDsupplied is not a value supported by the implementation.<dt>[ENAMETOOLONG]<dd>Pathname resolution of a symbolic link produced an intermediate result whoselength exceeds {PATH_MAX}.</dl></blockquote><h4><a name = "tag_000_001_454"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_001_455"> </a>APPLICATION USAGE</h4><blockquote>Because {_POSIX_CHOWN_RESTRICTED} is always definedwith a value other than -1 on XSI-conformantsystems, the error [EPERM] is always returned if the effective user ID doesnot match the owner of the file, or the calling process does not haveappropriate privileges.</blockquote><h4><a name = "tag_000_001_456"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_001_457"> </a>SEE ALSO</h4><blockquote><i><a href="chmod.html">chmod()</a></i>,<i><a href="systypes.h.html"><sys/types.h></a></i>,<i><a href="unistd.h.html"><unistd.h></a></i>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from Issue 1 of the SVID.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -