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

252 lines
6.7 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>getgrnam()--Get Group Information Using Group Name</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>getgrnam()--Get Group Information Using Group Name</h2>
<div class="box" style="width: 70%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;grp.h&gt;
struct group *getgrnam(const char <em>*name</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>getgrnam()</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>name</em>.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong><em>name</em></strong></dt>
<dd>(Input) A pointer to a group profile name.</dd>
</dl>
<br>
<h3>Authorities</h3>
<p>*READ authority is required to the user profile associated with the <em>
name</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>getgrnam()</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>
getgrgid()</strong> function. The <samp>struct group</samp> has the following
elements:<br>
<br>
<table border>
<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>
</dd>
<dt><em>NULL pointer</em></dt>
<dd><strong>getgrnam</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>getgrnam()</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>name</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#EDAMAGE">EDAMAGE</a>]</em></td>
<td align="left" valign="top">
<p>The user profile associated with the group name or an internal system object
is damaged.</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>name</em> was not found or the
profile name specified is not a group profile.
</td>
</tr>
<tr>
<td align="left" valign="top">
<em>[<a href="unix14.htm#EUNKNOWN">EUNKNOWN</a>]</em></td>
<td align="left" valign="top">
<p>Unknown system state. Check the job log for a CPF9872 message.</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="gtgrnamr.htm">getgrnam_r()</a>--Get Group Information Using Group
Name</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 group GROUP1. The
gid is 91. 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 = getgrnam("GROUP1")))
perror("getgrnam() 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>