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 \- パスワードファイルのエントリを
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)):
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
91 .\"O The \fIpasswd\fP structure is defined in
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
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 を保持できるバッファ
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.
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.
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);