Files
2024-02-19 00:21:47 -05:00

190 lines
5.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>fchown</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="fchown"></a> <a name="tag_03_139"></a><!-- fchown -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_139_01"></a>NAME</h4>
<blockquote>fchown - change owner and group of a file</blockquote>
<h4><a name="tag_03_139_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/unistd.h.html">unistd.h</a>&gt;<br>
<br>
int fchown(int</tt> <i>fildes</i><tt>, uid_t</tt> <i>owner</i><tt>, gid_t</tt> <i>group</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_139_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>fchown</i>() function shall be equivalent to <a href="../functions/chown.html"><i>chown</i>()</a> except that the file
whose owner and group are changed is specified by the file descriptor <i>fildes</i>.</p>
</blockquote>
<h4><a name="tag_03_139_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>fchown</i>() shall return 0. Otherwise, it shall return -1 and set <i>errno</i> to indicate the
error.</p>
</blockquote>
<h4><a name="tag_03_139_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>fchown</i>() function shall fail if:</p>
<dl compact>
<dt>[EBADF]</dt>
<dd>The <i>fildes</i> argument is not an open file descriptor.</dd>
<dt>[EPERM]</dt>
<dd>The effective user ID does not match the owner of the file or the process does not have appropriate privilege and
_POSIX_CHOWN_RESTRICTED indicates that such privilege is required.</dd>
<dt>[EROFS]</dt>
<dd>The file referred to by <i>fildes</i> resides on a read-only file system.</dd>
</dl>
<p>The <i>fchown</i>() function may fail if:</p>
<dl compact>
<dt>[EINVAL]</dt>
<dd>The owner or group ID is not a value supported by the implementation. The <i>fildes</i> argument refers to a pipe or socket
<sup>[<a href="javascript:open_code('XSR')">XSR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
&nbsp;or an <a href="../functions/fattach.html"><i>fattach</i>()</a>-ed STREAM <img src="../images/opt-end.gif" alt="[Option End]"
border="0"> &nbsp;and the implementation disallows execution of <i>fchown</i>() on a pipe.</dd>
<dt>[EIO]</dt>
<dd>A physical I/O error has occurred.</dd>
<dt>[EINTR]</dt>
<dd>The <i>fchown</i>() function was interrupted by a signal which was caught.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_139_06"></a>EXAMPLES</h4>
<blockquote>
<h5><a name="tag_03_139_06_01"></a>Changing the Current Owner of a File</h5>
<p>The following example shows how to change the owner of a file named <b>/home/cnd/mod1</b> to &quot;jones&quot; and the group to
&quot;cnd&quot;.</p>
<p>The numeric value for the user ID is obtained by extracting the user ID from the user database entry associated with &quot;jones&quot;.
Similarly, the numeric value for the group ID is obtained by extracting the group ID from the group database entry associated with
&quot;cnd&quot;. This example assumes the calling program has appropriate privileges.</p>
<pre>
<tt>#include &lt;sys/types.h&gt;
#include &lt;unistd.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;pwd.h&gt;
#include &lt;grp.h&gt;
<br>
struct passwd *pwd;
struct group *grp;
int fildes;
...
fildes = open("/home/cnd/mod1", O_RDWR);
pwd = getpwnam("jones");
grp = getgrnam("cnd");
fchown(fildes, pwd-&gt;pw_uid, grp-&gt;gr_gid);
</tt>
</pre>
</blockquote>
<h4><a name="tag_03_139_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_139_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_139_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_139_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="chown.html"><i>chown</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_139_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4, Version 2.</p>
</blockquote>
<h4><a name="tag_03_139_12"></a>Issue 5</h4>
<blockquote>
<p>Moved from X/OPEN UNIX extension to BASE.</p>
</blockquote>
<h4><a name="tag_03_139_13"></a>Issue 6</h4>
<blockquote>
<p>The following changes were made to align with the IEEE&nbsp;P1003.1a draft standard:</p>
<ul>
<li>
<p>Clarification is added that a call to <i>fchown</i>() may not be allowed on a pipe.</p>
</li>
</ul>
<p>The <i>fchown</i>() function is now defined as mandatory.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>