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 2007-07-26 "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)):
50 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
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).
79 ¤Î¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤǤ¢¤ë¡£
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
96 ¤Ë¤ª¤¤¤Æ°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
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 The nonreentrant functions return a pointer to static storage,
114 .\"O where this static storage contains further pointers to group
115 .\"O name, password and members.
116 ¥ê¥¨¥ó¥È¥é¥ó¥È¤Ç¤Ê¤¤´Ø¿ô¤ÏÀÅŪ¤Ê³ÊǼÎΰè¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
117 ¤³¤ÎÀÅŪ¤Ê³ÊǼÎΰè¤Ë¤Ï¡¢¹¹¤Ë¥°¥ë¡¼¥×̾¡¦¥Ñ¥¹¥ï¡¼¥É¡¦
118 ¥á¥ó¥Ð¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬´Þ¤Þ¤ì¤ë¡£
119 .\"O The reentrant functions described here return all of that in
120 .\"O caller-provided buffers.
121 .\"O First of all there is the buffer
123 .\"O that can hold a \fIstruct group\fP.
124 .\"O And next the buffer
128 .\"O that can hold additional strings.
129 ¤³¤³¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ë¥ê¥¨¥ó¥È¥é¥ó¥È¤Ê´Ø¿ô¤Ï¡¢
130 ¸Æ¤Ó½Ð¤·Â¦¤«¤éÄ󶡤µ¤ì¤ë¥Ð¥Ã¥Õ¥¡¤Ë¥°¥ë¡¼¥×̾¤Ê¤ÉÁ´¤Æ¤òÊÖ¤¹¡£
131 ºÇ½é¤Î°ú¤¿ô¤È¤·¤Æ \fIstruct group\fP ¤òÊÝ»ý¤Ç¤¤ë¥Ð¥Ã¥Õ¥¡
134 ¼¡¤Ë¤½¤Î¾¤Îʸ»úÎó¤òÊÝ»ý¤Ç¤¤ë¥µ¥¤¥º
139 .\"O The result of these functions, the \fIstruct group\fP read from the stream,
140 .\"O is stored in the provided buffer
142 .\"O and a pointer to this \fIstruct group\fP is returned in
144 ¤³¤ì¤é¤Î´Ø¿ô¤Î·ë²Ì (¥¹¥È¥ê¡¼¥à¤«¤éÆɤ߹þ¤Þ¤ì¤¿ \fIstruct group\fP) ¤Ï¡¢
147 ¤Ë³ÊǼ¤µ¤ì¡¢¤³¤Î \fIstruct group\fP ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ï
150 .\"O .SH "RETURN VALUE"
152 .\"O On success, these functions return 0 and
154 .\"O is a pointer to the \fIstruct group\fP.
155 À®¸ù¤·¤¿¾ì¹ç¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï 0 ¤òÊÖ¤·¡¢
157 ¤Ï \fIstruct group\fP ¤Ø¤Î¥Ý¥¤¥ó¥¿¤È¤Ê¤ë¡£
158 .\"O On error, these functions return an error value and
161 ¥¨¥é¡¼¤Î¾ì¹ç¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï¥¨¥é¡¼ÃͤòÊÖ¤·¡¢
168 .\"O No more entries.
172 .\"O Insufficient buffer space supplied.
173 .\"O Try again with larger buffer.
174 ½½Ê¬¤Ê¥Ð¥Ã¥Õ¥¡¶õ´Ö¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤Ê¤¤¡£
175 ¤â¤Ã¤ÈÂ礤ʥХåե¡¤ÇºÆÅټ¹Ԥ¹¤ë¤³¤È¡£
176 .\"O .SH "CONFORMING TO"
178 .\"O These functions are GNU extensions, done in a style resembling
179 .\"O the POSIX version of functions like
180 .\"O .BR getpwnam_r (3).
181 ¤³¤ì¤é¤Î´Ø¿ô¤Ï GNU ³ÈÄ¥¤Ç¤¢¤ê¡¢POSIX ÈǤδؿô
184 .\"O Other systems use prototype
185 ¾¤Î¥·¥¹¥Æ¥à¤Ç¤Ï°Ê²¼¤Î¥×¥í¥È¥¿¥¤¥×¤¬»È¤ï¤ì¤Æ¤¤¤ë¡£
189 struct group *getgrent_r(struct group *grp, char *buf,
195 ¤è¤êÎɤ¤¤â¤Î¤Ç¤Ï¡¢°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
199 int getgrent_r(struct group *grp, char *buf, int buflen,
206 .\"O .BR getgrent_r ()
207 .\"O is not really reentrant since it shares the reading position
208 .\"O in the stream with all other threads.
211 ¤ÏËÜÅö¤Î¥ê¥¨¥ó¥È¥é¥ó¥È¤Ç¤Ï¤Ê¤¤¡£
212 ¤Ê¤¼¤Ê¤é¡¢¥¹¥È¥ê¡¼¥à¤ÎÆɤ߹þ¤ß°ÌÃÖ¤ò
213 ¾¤ÎÁ´¤Æ¤Î¥¹¥ì¥Ã¥É¤È¶¦Í¤·¤Æ¤¤¤ë¤¿¤á¤Ç¤¢¤ë¡£
226 struct group grp, *grpp;
232 i = getgrent_r(&grp, buf, BUFLEN, &grpp);
235 printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid);
237 if (grpp\->gr_mem[i] == NULL)
239 printf(" %s", grpp\->gr_mem[i]);
247 .\"O .\" perhaps add error checking - should use strerror_r
248 .\" ¤¿¤Ö¤ó¥¨¥é¡¼¥Á¥§¥Ã¥¯¤òÄɲ䷤ơ¢strerror_r ¤ò»È¤¦¤Ù¤¤À¤í¤¦¡£
249 .\" #include <errno.h>
250 .\" #include <stdlib.h>
254 .\" printf("getgrent_r: %s", strerror(i));
255 .\" exit(EXIT_FAILURE);