~ubuntu-branches/ubuntu/precise/manpages-posix/precise

1 by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages.
1
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved 
2 by Francesco Paolo Lovergine
* Alligned to linux main manpages edition.
2
.TH "GETGRGID" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
1 by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages.
3
.\" getgrgid 
4
.SH NAME
5
getgrgid, getgrgid_r \- get group database entry for a group ID
6
.SH SYNOPSIS
7
.LP
8
\fB#include <grp.h>
9
.br
10
.sp
11
struct group *getgrgid(gid_t\fP \fIgid\fP\fB);
12
.br
13
\fP
14
.LP
15
\fBint getgrgid_r(gid_t\fP \fIgid\fP\fB, struct group *\fP\fIgrp\fP\fB,
16
char
17
*\fP\fIbuffer\fP\fB,
18
.br
19
\ \ \ \ \ \  size_t\fP \fIbufsize\fP\fB, struct group **\fP\fIresult\fP\fB);
20
\fP
21
\fB
22
.br
23
\fP
24
.SH DESCRIPTION
25
.LP
26
The \fIgetgrgid\fP() function shall search the group database for
27
an entry with a matching \fIgid\fP.
28
.LP
29
The \fIgetgrgid\fP() function need not be reentrant. A function that
30
is not required to be reentrant is not required to be
31
thread-safe.
32
.LP
33
The \fIgetgrgid_r\fP() function shall update the \fBgroup\fP structure
34
pointed to by \fIgrp\fP and store a pointer to that
35
structure at the location pointed to by \fIresult\fP. The structure
36
shall contain an entry from the group database with a matching
37
\fIgid\fP. Storage referenced by the group structure is allocated
38
from the memory provided with the \fIbuffer\fP parameter, which
39
is \fIbufsize\fP bytes in size. The maximum size needed for this buffer
40
can be determined with the {_SC_GETGR_R_SIZE_MAX} \fIsysconf\fP()
41
parameter. A NULL pointer shall be returned at the location pointed
42
to by
43
\fIresult\fP on error or if the requested entry is not found. 
44
.SH RETURN VALUE
45
.LP
46
Upon successful completion, \fIgetgrgid\fP() shall return a pointer
47
to a \fBstruct group\fP with the structure defined in \fI<grp.h>\fP
48
with a matching entry if one is found. The \fIgetgrgid\fP() function
49
shall
50
return a null pointer if either the requested entry was not found,
51
or an error occurred. On error, \fIerrno\fP shall be set to
52
indicate the error.
53
.LP
54
The return value may point to a static area which is overwritten by
55
a subsequent call to \fIgetgrent\fP(), \fIgetgrgid\fP(), or \fIgetgrnam\fP().
56
.LP
57
If successful, the \fIgetgrgid_r\fP() function shall return zero;
58
otherwise, an error number shall be returned to indicate the
59
error. 
60
.SH ERRORS
61
.LP
62
The \fIgetgrgid\fP() and \fIgetgrgid_r\fP() functions may fail if:
63
.TP 7
64
.B EIO
65
An I/O error has occurred.
66
.TP 7
67
.B EINTR
68
A signal was caught during \fIgetgrgid\fP().
69
.TP 7
70
.B EMFILE
71
{OPEN_MAX} file descriptors are currently open in the calling process.
72
.TP 7
73
.B ENFILE
74
The maximum allowable number of files is currently open in the system.
75
.sp
76
.LP
77
The \fIgetgrgid_r\fP() function may fail if: 
78
.TP 7
79
.B ERANGE
80
Insufficient storage was supplied via \fIbuffer\fP and \fIbufsize\fP
81
to contain the data to be referenced by the resulting
82
\fBgroup\fP structure. 
83
.sp
84
.LP
85
\fIThe following sections are informative.\fP
86
.SH EXAMPLES
87
.SS Finding an Entry in the Group Database
88
.LP
89
The following example uses \fIgetgrgid\fP() to search the group database
90
for a group ID that was previously stored in a
91
\fBstat\fP structure, then prints out the group name if it is found.
92
If the group is not found, the program prints the numeric
93
value of the group for the entry.
94
.sp
95
.RS
96
.nf
97
98
\fB#include <sys/types.h>
99
#include <grp.h>
100
#include <stdio.h>
101
\&...
102
struct stat statbuf;
103
struct group *grp;
104
\&...
105
if ((grp = getgrgid(statbuf.st_gid)) != NULL)
106
    printf(" %-8.8s", grp->gr_name);
107
else
108
    printf(" %-8d", statbuf.st_gid);
109
\&...
110
\fP
111
.fi
112
.RE
113
.SH APPLICATION USAGE
114
.LP
115
Applications wishing to check for error situations should set \fIerrno\fP
116
to 0 before calling \fIgetgrgid\fP(). If
117
\fIerrno\fP is set on return, an error occurred.
118
.LP
119
The \fIgetgrgid_r\fP() function is thread-safe and shall return values
120
in a user-supplied buffer instead of possibly using a
121
static data area that may be overwritten by each call.
122
.SH RATIONALE
123
.LP
124
None.
125
.SH FUTURE DIRECTIONS
126
.LP
127
None.
128
.SH SEE ALSO
129
.LP
130
\fIendgrent\fP() , \fIgetgrnam\fP() , the Base Definitions volume
131
of
132
IEEE\ Std\ 1003.1-2001, \fI<grp.h>\fP, \fI<limits.h>\fP, \fI<sys/types.h>\fP
133
.SH COPYRIGHT
134
Portions of this text are reprinted and reproduced in electronic form
135
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
136
-- Portable Operating System Interface (POSIX), The Open Group Base
137
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
138
Electrical and Electronics Engineers, Inc and The Open Group. In the
139
event of any discrepancy between this version and the original IEEE and
140
The Open Group Standard, the original IEEE and The Open Group Standard
141
is the referee document. The original Standard can be obtained online at
142
http://www.opengroup.org/unix/online.html .