1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 .\" GNU General Public License for more details.
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
23 .\" Japanese Version Copyright (c) 2004 Yuichi SATO
24 .\" all rights reserved.
25 .\" Translated Thu Jul 29 02:26:07 JST 2004
26 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
28 .TH GETGRENT_R 3 2010-10-21 "GNU" "Linux Programmer's Manual"
31 .\"O getgrent_r, fgetgrent_r \- get group file entry reentrantly
32 getgrent_r, fgetgrent_r \- グループファイルエントリをリエントラント (reentrant) に取り出す
38 .BI "int getgrent_r(struct group *" gbuf ", char *" buf ,
40 .BI " size_t " buflen ", struct group **" gbufp );
42 .BI "int fgetgrent_r(FILE *" fp ", struct group *" gbuf ", char *" buf ,
44 .BI " size_t " buflen ", struct group **" gbufp );
48 .\"O Feature Test Macro Requirements for glibc (see
49 .\"O .BR feature_test_macros (7)):
51 .RB ( feature_test_macros (7)
57 .\" FIXME . The FTM requirements seem inconsistent here. File a glibc bug?
64 .\"O .BR getgrent_r ()
66 .\"O .BR fgetgrent_r ()
67 .\"O are the reentrant versions of
70 .\"O .BR fgetgrent (3).
80 .\"O The former reads the next group entry from the stream initialized by
81 .\"O .BR setgrent (3).
84 によって初期化されたストリームから、次のグループファイルのエントリを読み込む。
85 .\"O The latter reads the next group entry from the stream
89 から次のグループファイルのエントリを読み込む。
91 .\"O The \fIgroup\fP structure is defined in
101 .\"O char *gr_name; /* group name */
102 .\"O char *gr_passwd; /* group password */
103 .\"O gid_t gr_gid; /* group ID */
104 .\"O char **gr_mem; /* group members */
105 char *gr_name; /* グループ名 */
106 char *gr_passwd; /* グループパスワード */
107 gid_t gr_gid; /* グループ ID */
108 char **gr_mem; /* グループメンバ */
113 .\"O For more information about the fields of this structure, see
119 .\"O The nonreentrant functions return a pointer to static storage,
120 .\"O where this static storage contains further pointers to group
121 .\"O name, password and members.
122 リエントラントでない関数は静的な格納領域へのポインタを返す。
123 この静的な格納領域には、更にグループ名・パスワード・
125 .\"O The reentrant functions described here return all of that in
126 .\"O caller-provided buffers.
127 .\"O First of all there is the buffer
129 .\"O that can hold a \fIstruct group\fP.
130 .\"O And next the buffer
134 .\"O that can hold additional strings.
135 ここで説明されているリエントラントな関数は、
136 呼び出し側から提供されるバッファにグループ名など全てを返す。
137 最初の引き数として \fIstruct group\fP を保持できるバッファ
145 .\"O The result of these functions, the \fIstruct group\fP read from the stream,
146 .\"O is stored in the provided buffer
148 .\"O and a pointer to this \fIstruct group\fP is returned in
150 これらの関数の結果 (ストリームから読み込まれた \fIstruct group\fP) は、
153 に格納され、この \fIstruct group\fP へのポインタは
156 .\"O .SH "RETURN VALUE"
158 .\"O On success, these functions return 0 and
160 .\"O is a pointer to the \fIstruct group\fP.
161 成功した場合、これらの関数は 0 を返し、
163 は \fIstruct group\fP へのポインタとなる。
164 .\"O On error, these functions return an error value and
167 エラーの場合、これらの関数はエラー値を返し、
174 .\"O No more entries.
178 .\"O Insufficient buffer space supplied.
179 .\"O Try again with larger buffer.
182 .\"O .SH "CONFORMING TO"
184 .\"O These functions are GNU extensions, done in a style resembling
185 .\"O the POSIX version of functions like
186 .\"O .BR getpwnam_r (3).
187 これらの関数は GNU 拡張であり、POSIX 版の関数
190 .\"O Other systems use prototype
191 他のシステムでは以下のプロトタイプが使われている。
195 struct group *getgrent_r(struct group *grp, char *buf,
201 より良いものでは、以下のようになっている。
205 int getgrent_r(struct group *grp, char *buf, int buflen,
212 .\"O .BR getgrent_r ()
213 .\"O is not really reentrant since it shares the reading position
214 .\"O in the stream with all other threads.
219 他の全てのスレッドと共有しているためである。
232 struct group grp, *grpp;
238 i = getgrent_r(&grp, buf, BUFLEN, &grpp);
241 printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid);
243 if (grpp\->gr_mem[i] == NULL)
245 printf(" %s", grpp\->gr_mem[i]);
253 .\"O .\" perhaps add error checking - should use strerror_r
254 .\" たぶんエラーチェックを追加して、strerror_r を使うべきだろう。
255 .\" #include <errno.h>
256 .\" #include <stdlib.h>
260 .\" printf("getgrent_r: %s", strerror(i));
261 .\" exit(EXIT_FAILURE);