Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/getgroups.html
2024-02-19 00:21:47 -05:00

189 lines
6.8 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>getgroups</title>
</head>
<body bgcolor="white">
<basefont size="3"> <a name="getgroups"></a> <a name="tag_03_224"></a><!-- getgroups -->
<!--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_224_01"></a>NAME</h4>
<blockquote>getgroups - get supplementary group IDs</blockquote>
<h4><a name="tag_03_224_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 getgroups(int</tt> <i>gidsetsize</i><tt>, gid_t</tt> <i>grouplist</i><tt>[]);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_224_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>getgroups</i>() function shall fill in the array <i>grouplist</i> with the current supplementary group IDs of the calling
process. It is implementation-defined whether <i>getgroups</i>() also returns the effective group ID in the <i>grouplist</i>
array.</p>
<p>The <i>gidsetsize</i> argument specifies the number of elements in the array <i>grouplist</i>. The actual number of group IDs
stored in the array shall be returned. The values of array entries with indices greater than or equal to the value returned are
undefined.</p>
<p>If <i>gidsetsize</i> is 0, <i>getgroups</i>() shall return the number of group IDs that it would otherwise return without
modifying the array pointed to by <i>grouplist</i>.</p>
<p>If the effective group ID of the process is returned with the supplementary group IDs, the value returned shall always be
greater than or equal to one and less than or equal to the value of {NGROUPS_MAX}+1.</p>
</blockquote>
<h4><a name="tag_03_224_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, the number of supplementary group IDs shall be returned. A return value of -1 indicates failure and
<i>errno</i> shall be set to indicate the error.</p>
</blockquote>
<h4><a name="tag_03_224_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>getgroups</i>() function shall fail if:</p>
<dl compact>
<dt>[EINVAL]</dt>
<dd>The <i>gidsetsize</i> argument is non-zero and less than the number of group IDs that would have been returned.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_224_06"></a>EXAMPLES</h4>
<blockquote>
<h5><a name="tag_03_224_06_01"></a>Getting the Supplementary Group IDs of the Calling Process</h5>
<p>The following example places the current supplementary group IDs of the calling process into the <i>group</i> array.</p>
<pre>
<tt>#include &lt;sys/types.h&gt;
#include &lt;unistd.h&gt;
...
gid_t *group;
int nogroups;
long ngroups_max;
<br>
ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1;
group = (gid_t *)malloc(ngroups_max *sizeof(gid_t));
<br>
ngroups = getgroups(ngroups_max, group);
</tt>
</pre>
</blockquote>
<h4><a name="tag_03_224_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_224_08"></a>RATIONALE</h4>
<blockquote>
<p>The related function <i>setgroups</i>() is a privileged operation and therefore is not covered by this volume of
IEEE&nbsp;Std&nbsp;1003.1-2001.</p>
<p>As implied by the definition of supplementary groups, the effective group ID may appear in the array returned by
<i>getgroups</i>() or it may be returned only by <a href="../functions/getegid.html"><i>getegid</i>()</a>. Duplication may exist,
but the application needs to call <a href="../functions/getegid.html"><i>getegid</i>()</a> to be sure of getting all of the
information. Various implementation variations and administrative sequences cause the set of groups appearing in the result of
<i>getgroups</i>() to vary in order and as to whether the effective group ID is included, even when the set of groups is the same
(in the mathematical sense of &quot;set&quot;). (The history of a process and its parents could affect the details of the result.)</p>
<p>Application writers should note that {NGROUPS_MAX} is not necessarily a constant on all implementations.</p>
</blockquote>
<h4><a name="tag_03_224_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_224_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="getegid.html"><i>getegid</i>()</a> , <a href="setgid.html"><i>setgid</i>()</a> , the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a>, <a href=
"../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_224_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 3. Included for alignment with the POSIX.1-1988 standard.</p>
</blockquote>
<h4><a name="tag_03_224_12"></a>Issue 5</h4>
<blockquote>
<p>Normative text previously in the APPLICATION USAGE section is moved to the DESCRIPTION.</p>
</blockquote>
<h4><a name="tag_03_224_13"></a>Issue 6</h4>
<blockquote>
<p>In the SYNOPSIS, the optional include of the <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> header is
removed.</p>
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
<ul>
<li>
<p>The requirement to include <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> has been removed. Although <a
href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> was required for conforming implementations of previous POSIX
specifications, it was not required for UNIX applications.</p>
</li>
<li>
<p>A return value of 0 is not permitted, because {NGROUPS_MAX} cannot be 0. This is a FIPS requirement.</p>
</li>
</ul>
<p>The following changes were made to align with the IEEE&nbsp;P1003.1a draft standard:</p>
<ul>
<li>
<p>Explanation added that the effective group ID may be included in the supplementary group list.</p>
</li>
</ul>
</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>