ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/getgrgid.htm

255 lines
6.6 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>getgrgid()--Get Group Information Using Group ID</title>
<!-- Begin Header Records ========================================== -->
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Change History: -->
<!-- file cleaned -->
<!-- Unix2 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!-- This file has undergone html cleanup on 05/14/02 by JET -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!--End Header Records --><!-- Java sync-link -->
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
</script>
<a name="Top_Of_Page"></a>
<h2>getgrgid()--Get Group Information Using Group ID</h2>
<div class="box" style="width: 70%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;grp.h&gt;
struct group *getgrgid(gid_t <em>gid</em>);
</pre>
&nbsp;&nbsp;Service Program Name: QSYPAPI<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: No<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>getgrgid()</strong> function returns a pointer to an object of
type <samp>struct group</samp> containing an entry from the user database with
a matching <em>GID</em>.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong><em>gid</em></strong></dt>
<dd>(Input) Group ID.</dd>
</dl>
<br>
<h3>Authorities</h3>
<p>*READ authority is required to the user profile associated with the <em>
gid</em>. If the user does not have *READ authority, only the name of the group
and the group ID values are returned.</p>
<br>
<h3>Return Value</h3>
<dl compact>
<dt><em>struct group *</em></dt>
<dd><strong>getgrgid()</strong> was successful. The return value points to
static data of the format <samp>struct group</samp>, which is defined in the
<strong>grp.h</strong> header file. This storage is overwritten on each call to
this function. This static storage area is also used by the <strong>
getgrnam()</strong> function. The <samp>struct group</samp> has the following
elements:<br>
<br>
<table border cellpadding="5">
<!-- cols="10 10 80" -->
<tr>
<td align="left" valign="top" width="10%">char *</td>
<td align="left" valign="top" width="10%">gr_name</td>
<td align="left" valign="top" width="80%">Name of the group</td>
</tr>
<tr>
<td align="left" valign="top" width="10%">gid_t</td>
<td align="left" valign="top" width="10%">gr_gid</td>
<td align="left" valign="top" width="80%">Group ID</td>
</tr>
<tr>
<td align="left" valign="top" width="10%">char **</td>
<td align="left" valign="top" width="10%">gr_mem</td>
<td align="left" valign="top" width="80%">A null-terminated list of pointers to
the individual member profile names. If the group profile does not have any
members or if the caller does not have *READ authority to the group profile,
the list will be empty.</td>
</tr>
</table>
<br>
</dd>
<dt><em>NULL pointer</em></dt>
<dd><strong>getgrgid</strong> was not successful. The <em>errno</em> global
variable is set to indicate the error.</dd>
</dl>
<br>
<h3>Error Conditions</h3>
<p>If <strong>getgrgid()</strong> is not successful, <em>errno</em> usually
indicates one of the following errors. Under some conditions, <em>errno</em>
could indicate an error other than those listed here.</p>
<table cellpadding="5">
<!-- cols="25 75" -->
<tr>
<th align="left" valign="bottom">Error condition</th>
<th align="left" valign="bottom">Additional information</th>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EAGAIN">EAGAIN</a>]</em></td>
<td align="left" valign="top">
<p>The user profile associated with the <em>GID</em> is currently locked by
another process.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EC2">EC2</a>]</em></td>
<td align="left" valign="top">
<p>Detected pointer that is not valid.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EINVAL">EINVAL</a>]</em></td>
<td align="left" valign="top">
<p>Value is not valid. Check the job log for messages.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENOENT">ENOENT</a>]</em></td>
<td align="left" valign="top">
The user profile associated with the <em>GID</em> was not found.
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENOMEM">ENOMEM</a>]</em></td>
<td align="left" valign="top">
<p>The user profile associated with the <em>GID</em> has exceeded its storage
limit.</p>
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#ENOSPC">ENOSPC</a>]</em></td>
<td align="left" valign="top">
<p>Machine storage limit exceeded.</p>
</td>
</tr>
</table>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>grp.h</strong>&gt; file (see <a href="unix13.htm">Header
Files for UNIX-Type Functions</a>)<br>
</li>
<li><a href="gtgrgidr.htm">getgrgid_r()</a>--Get Group Information Using Group
ID</li>
</ul>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<p>The following example gets the group information for the gid of 91. The
group name is GROUP1. There are two group members, CLIFF and PATRICK.</p>
<pre>
#include &lt;grp.h&gt;
#include &lt;stdio.h&gt;
main()
{
struct group *grp;
short int lp;
if (NULL == (grp = getgrgid(91)))
perror("getgrgid() error.");
else
{
printf("The group name is: %s\n", grp-&gt;gr_name);
printf("The gid is: %u\n", grp-&gt;gr_gid);
for (lp = 1; NULL != *(grp-&gt;gr_mem); lp++, (grp-&gt;gr_mem)++)
printf("Group member %d is: %s\n", lp, *(grp-&gt;gr_mem));
}
}
</pre>
<p><strong>Output:</strong></p>
<pre>
The group name is: GROUP1
The gid is: 91
Group member 1 is: CLIFF
Group member 2 is: PATRICK
</pre>
<hr>
API introduced: V3R1 <br>
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
</tr>
</table>
</center>
</body>
</html>