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

240 lines
9.4 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>getgrgid</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="getgrgid"></a> <a name="tag_03_222"></a><!-- getgrgid -->
<!--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_222_01"></a>NAME</h4>
<blockquote>getgrgid, getgrgid_r - get group database entry for a group ID</blockquote>
<h4><a name="tag_03_222_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/grp.h.html">grp.h</a>&gt;<br>
<br>
struct group *getgrgid(gid_t</tt> <i>gid</i><tt>);<br>
</tt></code></p>
<div class="box"><code><tt><sup>[<a href="javascript:open_code('TSF')">TSF</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> int getgrgid_r(gid_t</tt> <i>gid</i><tt>, struct group *</tt><i>grp</i><tt>, char
*</tt><i>buffer</i><tt>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size_t</tt> <i>bufsize</i><tt>, struct group **</tt><i>result</i><tt>); <img src=
"../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
<tt><br>
</tt></blockquote>
<h4><a name="tag_03_222_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>getgrgid</i>() function shall search the group database for an entry with a matching <i>gid</i>.</p>
<p>The <i>getgrgid</i>() function need not be reentrant. A function that is not required to be reentrant is not required to be
thread-safe.</p>
<p><sup>[<a href="javascript:open_code('TSF')">TSF</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
The <i>getgrgid_r</i>() function shall update the <b>group</b> structure pointed to by <i>grp</i> and store a pointer to that
structure at the location pointed to by <i>result</i>. The structure shall contain an entry from the group database with a matching
<i>gid</i>. Storage referenced by the group structure is allocated from the memory provided with the <i>buffer</i> parameter, which
is <i>bufsize</i> bytes in size. The maximum size needed for this buffer can be determined with the {_SC_GETGR_R_SIZE_MAX} <a href=
"../functions/sysconf.html"><i>sysconf</i>()</a> parameter. A NULL pointer shall be returned at the location pointed to by
<i>result</i> on error or if the requested entry is not found. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
</blockquote>
<h4><a name="tag_03_222_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>getgrgid</i>() shall return a pointer to a <b>struct group</b> with the structure defined in <a
href="../basedefs/grp.h.html"><i>&lt;grp.h&gt;</i></a> with a matching entry if one is found. The <i>getgrgid</i>() function shall
return a null pointer if either the requested entry was not found, or an error occurred. On error, <i>errno</i> shall be set to
indicate the error.</p>
<p>The return value may point to a static area which is overwritten by a subsequent call to <a href=
"../functions/getgrent.html"><i>getgrent</i>()</a>, <i>getgrgid</i>(), or <a href=
"../functions/getgrnam.html"><i>getgrnam</i>()</a>.</p>
<p><sup>[<a href="javascript:open_code('TSF')">TSF</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
If successful, the <i>getgrgid_r</i>() function shall return zero; otherwise, an error number shall be returned to indicate the
error. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
</blockquote>
<h4><a name="tag_03_222_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>getgrgid</i>() and <i>getgrgid_r</i>() functions may fail if:</p>
<dl compact>
<dt>[EIO]</dt>
<dd>An I/O error has occurred.</dd>
<dt>[EINTR]</dt>
<dd>A signal was caught during <i>getgrgid</i>().</dd>
<dt>[EMFILE]</dt>
<dd>{OPEN_MAX} file descriptors are currently open in the calling process.</dd>
<dt>[ENFILE]</dt>
<dd>The maximum allowable number of files is currently open in the system.</dd>
</dl>
<p><sup>[<a href="javascript:open_code('TSF')">TSF</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
The <i>getgrgid_r</i>() function may fail if: <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
<dl compact>
<dt>[ERANGE]</dt>
<dd><sup>[<a href="javascript:open_code('TSF')">TSF</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
Insufficient storage was supplied via <i>buffer</i> and <i>bufsize</i> to contain the data to be referenced by the resulting
<b>group</b> structure. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_222_06"></a>EXAMPLES</h4>
<blockquote>
<h5><a name="tag_03_222_06_01"></a>Finding an Entry in the Group Database</h5>
<p>The following example uses <i>getgrgid</i>() to search the group database for a group ID that was previously stored in a
<b>stat</b> structure, then prints out the group name if it is found. If the group is not found, the program prints the numeric
value of the group for the entry.</p>
<pre>
<tt>#include &lt;sys/types.h&gt;
#include &lt;grp.h&gt;
#include &lt;stdio.h&gt;
...
struct stat statbuf;
struct group *grp;
...
if ((grp = getgrgid(statbuf.st_gid)) != NULL)
printf(" %-8.8s", grp-&gt;gr_name);
else
printf(" %-8d", statbuf.st_gid);
...
</tt>
</pre>
</blockquote>
<h4><a name="tag_03_222_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>Applications wishing to check for error situations should set <i>errno</i> to 0 before calling <i>getgrgid</i>(). If
<i>errno</i> is set on return, an error occurred.</p>
<p>The <i>getgrgid_r</i>() function is thread-safe and shall return values in a user-supplied buffer instead of possibly using a
static data area that may be overwritten by each call.</p>
</blockquote>
<h4><a name="tag_03_222_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_222_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_222_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="endgrent.html"><i>endgrent</i>()</a> , <a href="getgrnam.html"><i>getgrnam</i>()</a> , the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/grp.h.html"><i>&lt;grp.h&gt;</i></a>, <a href=
"../basedefs/limits.h.html"><i>&lt;limits.h&gt;</i></a>, <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_222_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 1. Derived from System V Release 2.0.</p>
</blockquote>
<h4><a name="tag_03_222_12"></a>Issue 5</h4>
<blockquote>
<p>Normative text previously in the APPLICATION USAGE section is moved to the RETURN VALUE section.</p>
<p>The <i>getgrgid_r</i>() function is included for alignment with the POSIX Threads Extension.</p>
<p>A note indicating that the <i>getgrgid</i>() function need not be reentrant is added to the DESCRIPTION.</p>
</blockquote>
<h4><a name="tag_03_222_13"></a>Issue 6</h4>
<blockquote>
<p>The <i>getgrgid_r</i>() function is marked as part of the Thread-Safe Functions option.</p>
<p>The Open Group Corrigendum U028/3 is applied, correcting text in the DESCRIPTION describing matching the <i>gid</i>.</p>
<p>In the DESCRIPTION, the note about reentrancy is expanded to cover thread-safety.</p>
<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>In the RETURN VALUE section, the requirement to set <i>errno</i> on error is added.</p>
</li>
<li>
<p>The [EIO], [EINTR], [EMFILE], and [ENFILE] optional error conditions are added.</p>
</li>
</ul>
<p>The APPLICATION USAGE section is updated to include a note on the thread-safe function and its avoidance of possibly using a
static data area.</p>
<p>IEEE PASC Interpretation 1003.1 #116 is applied, changing the description of the size of the buffer from <i>bufsize</i>
characters to bytes.</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>