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 Sun Aug 8 00:53:40 JST 2004
26 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
28 .TH GETPWENT_R 3 2010-10-21 "GNU" "Linux Programmer's Manual"
31 .\"O getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
32 getpwent_r, fgetpwent_r \- ¥Ñ¥¹¥ï¡¼¥É¥Õ¥¡¥¤¥ë¤Î¥¨¥ó¥È¥ê¤ò
33 ¥ê¥¨¥ó¥È¥é¥ó¥È¤Ç¼è¤ê½Ð¤¹
39 .BI "int getpwent_r(struct passwd *" pwbuf ", char *" buf ,
41 .BI " size_t " buflen ", struct passwd **" pwbufp );
43 .BI "int fgetpwent_r(FILE *" fp ", struct passwd *" pwbuf ", char *" buf ,
45 .BI " size_t " buflen ", struct passwd **" pwbufp );
49 .\"O Feature Test Macro Requirements for glibc (see
50 .\"O .BR feature_test_macros (7)):
51 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
52 .RB ( feature_test_macros (7)
57 _BSD_SOURCE || _SVID_SOURCE
64 .\"O .BR getpwent_r ()
66 .\"O .BR fgetpwent_r ()
67 .\"O are the reentrant versions of
70 .\"O .BR fgetpwent (3).
79 ¤Î¥ê¥¨¥ó¥È¥é¥ó¥È (reentrant) ÈǤǤ¢¤ë¡£
80 .\"O The former reads the next passwd entry from the stream initialized by
81 .\"O .BR setpwent (3).
84 ¤Ë¤è¤Ã¤Æ½é´ü²½¤µ¤ì¤¿¥¹¥È¥ê¡¼¥à¤«¤é¡¢¼¡¤Î¥Ñ¥¹¥ï¡¼¥É¥¨¥ó¥È¥ê¤òÆɤ߹þ¤à¡£
85 .\"O The latter reads the next passwd entry from the stream
89 ¤«¤é¼¡¤Î¥Ñ¥¹¥ï¡¼¥É¥¨¥ó¥È¥ê¤òÆɤ߹þ¤à¡£
91 .\"O The \fIpasswd\fP structure is defined in
96 ¤Ë¤ª¤¤¤Æ°Ê²¼¤Î¤è¤¦¤ËÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
101 .\"O char *pw_name; /* username */
102 .\"O char *pw_passwd; /* user password */
103 .\"O uid_t pw_uid; /* user ID */
104 .\"O gid_t pw_gid; /* group ID */
105 .\"O char *pw_gecos; /* user information */
106 .\"O char *pw_dir; /* home directory */
107 .\"O char *pw_shell; /* shell program */
108 char *pw_name; /* ¥æ¡¼¥¶Ì¾ */
109 char *pw_passwd; /* ¥æ¡¼¥¶¤Î¥Ñ¥¹¥ï¡¼¥É */
110 uid_t pw_uid; /* ¥æ¡¼¥¶ ID */
111 gid_t pw_gid; /* ¥°¥ë¡¼¥× ID */
112 char *pw_gecos; /* ¥æ¡¼¥¶¾ðÊó */
113 char *pw_dir; /* ¥Û¡¼¥à¥Ç¥£¥ì¥¯¥È¥ê */
114 char *pw_shell; /* ¥·¥§¥ë¥×¥í¥°¥é¥à */
119 .\"O For more information about the fields of this structure, see
121 ¤³¤Î¹½Â¤ÂΤΥե£¡¼¥ë¥É¤Î¾ÜºÙ¤Ï
125 .\"O The nonreentrant functions return a pointer to static storage,
126 .\"O where this static storage contains further pointers to user
127 .\"O name, password, gecos field, home directory and shell.
128 ¥ê¥¨¥ó¥È¥é¥ó¥È¤Ç¤Ê¤¤´Ø¿ô¤ÏÀÅŪ¤Ê³ÊǼÎΰè¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
129 ¤³¤ÎÀÅŪ¤Ê³ÊǼÎΰè¤Ë¤Ï¡¢¹¹¤Ë¥æ¡¼¥¶Ì¾¡¦¥Ñ¥¹¥ï¡¼¥É¡¦gecos ¥Õ¥£¡¼¥ë¥É¡¦
130 ¥Û¡¼¥à¥Ç¥£¥ì¥¯¥È¥ê¡¦¥·¥§¥ë¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬´Þ¤Þ¤ì¤ë¡£
131 .\"O The reentrant functions described here return all of that in
132 .\"O caller-provided buffers.
133 .\"O First of all there is the buffer
135 .\"O that can hold a \fIstruct passwd\fP.
136 .\"O And next the buffer
140 .\"O that can hold additional strings.
141 ¤³¤³¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ë¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤδؿô¤Ï¡¢
142 ¸Æ¤Ó½Ð¤·Â¦¤«¤éÄ󶡤µ¤ì¤ë¥Ð¥Ã¥Õ¥¡¤Ë¥æ¡¼¥¶Ì¾¤Ê¤ÉÁ´¤Æ¤òÊÖ¤¹¡£
143 ºÇ½é¤Î°ú¤¿ô¤È¤·¤Æ \fIstruct passwd\fP ¤òÊÝ»ý¤Ç¤¤ë¥Ð¥Ã¥Õ¥¡
146 ¼¡¤Ë¤½¤Î¾¤Îʸ»úÎó¤òÊÝ»ý¤Ç¤¤ë¥µ¥¤¥º
151 .\"O The result of these functions, the \fIstruct passwd\fP read from the stream,
152 .\"O is stored in the provided buffer
154 .\"O and a pointer to this \fIstruct passwd\fP is returned in
156 ¤³¤ì¤é¤Î´Ø¿ô¤Î·ë²Ì (¥¹¥È¥ê¡¼¥à¤«¤éÆɤ߹þ¤Þ¤ì¤¿ \fIstruct passwd\fP) ¤Ï¡¢
159 ¤Ë³ÊǼ¤µ¤ì¡¢¤³¤Î \fIstruct passwd\fP ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ï
162 .\"O .SH "RETURN VALUE"
164 .\"O On success, these functions return 0 and
166 .\"O is a pointer to the \fIstruct passwd\fP.
167 À®¸ù¤·¤¿¾ì¹ç¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï 0 ¤òÊÖ¤·¡¢
169 ¤Ï \fIstruct passwd\fP ¤Ø¤Î¥Ý¥¤¥ó¥¿¤È¤Ê¤ë¡£
170 ¥¨¥é¡¼¤Î¾ì¹ç¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï¥¨¥é¡¼ÃͤòÊÖ¤·¡¢
177 .\"O No more entries.
181 .\"O Insufficient buffer space supplied.
182 .\"O Try again with larger buffer.
183 ½½Ê¬¤Ê¥Ð¥Ã¥Õ¥¡¶õ´Ö¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤Ê¤¤¡£
184 ¤â¤Ã¤ÈÂ礤ʥХåե¡¤ÇºÆÅټ¹Ԥ¹¤ë¤³¤È¡£
185 .\"O .SH "CONFORMING TO"
187 .\"O These functions are GNU extensions, done in a style resembling
188 .\"O the POSIX version of functions like
189 .\"O .BR getpwnam_r (3).
190 ¤³¤ì¤é¤Î´Ø¿ô¤Ï GNU ³ÈÄ¥¤Ç¤¢¤ê¡¢POSIX ÈǤδؿô
193 .\"O Other systems use prototype
194 ¾¤Î¥·¥¹¥Æ¥à¤Ç¤Ï°Ê²¼¤Î¥×¥í¥È¥¿¥¤¥×¤¬»È¤ï¤ì¤Æ¤¤¤ë¡£
199 getpwent_r(struct passwd *pwd, char *buf, int buflen);
204 ¤è¤êÎɤ¤¤â¤Î¤Ç¤Ï¡¢°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
209 getpwent_r(struct passwd *pwd, char *buf, int buflen,
216 .\"O .BR getpwent_r ()
217 .\"O is not really reentrant since it shares the reading position
218 .\"O in the stream with all other threads.
221 ¤ÏËÜÅö¤Î¥ê¥¨¥ó¥È¥é¥ó¥È¤Ç¤Ï¤Ê¤¤¡£
222 ¤Ê¤¼¤Ê¤é¡¢¥¹¥È¥ê¡¼¥à¤ÎÆɤ߹þ¤ß°ÌÃÖ¤ò
223 ¾¤ÎÁ´¤Æ¤Î¥¹¥ì¥Ã¥É¤È¶¦Í¤·¤Æ¤¤¤ë¤¿¤á¤Ç¤¢¤ë¡£
235 struct passwd pw, *pwp;
241 i = getpwent_r(&pw, buf, BUFLEN, &pwp);
244 printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
245 pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
251 .\"O .\" perhaps add error checking - should use strerror_r
252 .\" ¤¿¤Ö¤ó¥¨¥é¡¼¥Á¥§¥Ã¥¯¤òÄɲ䷤ơ¢strerror_r ¤ò»È¤¦¤Ù¤¤À¤í¤¦¡£
253 .\" #include <errno.h>
254 .\" #include <stdlib.h>
258 .\" printf("getpwent_r: %s", strerror(i));
259 .\" exit(EXIT_SUCCESS);