OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / man3 / getpwent_r.3
1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
2 .\"
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.
7 .\"
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.
12 .\"
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.
17 .\"
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,
21 .\" USA.
22 .\"
23 .\"*******************************************************************
24 .\"
25 .\" This file was generated with po4a. Translate the source file.
26 .\"
27 .\"*******************************************************************
28 .TH GETPWENT_R 3 2010\-10\-21 GNU "Linux Programmer's Manual"
29 .SH 名前
30 getpwent_r, fgetpwent_r \- パスワードファイルのエントリを リエントラントで取り出す
31 .SH 書式
32 .nf
33 \fB#include <pwd.h>\fP
34 .sp
35 \fBint getpwent_r(struct passwd *\fP\fIpwbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
36 .br
37 \fB               size_t \fP\fIbuflen\fP\fB, struct passwd **\fP\fIpwbufp\fP\fB);\fP
38 .sp
39 \fBint fgetpwent_r(FILE *\fP\fIfp\fP\fB, struct passwd *\fP\fIpwbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
40 .br
41 \fB                size_t \fP\fIbuflen\fP\fB, struct passwd **\fP\fIpwbufp\fP\fB);\fP
42 .fi
43 .sp
44 .in -4n
45 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
46 .in
47 .sp
48 \fBgetpwent_r\fP(), _BSD_SOURCE || _SVID_SOURCE
49 .br
50 \fBfgetpwent_r\fP(): _SVID_SOURCE
51 .SH 説明
52 関数 \fBgetpwent_r\fP()  と \fBfgetpwent_r\fP()  は \fBgetpwent\fP(3)  と \fBfgetpwent\fP(3)
53 のリエントラント (reentrant) 版である。 前者は、 \fBsetpwent\fP(3)
54 によって初期化されたストリームから、次のパスワードエントリを読み込む。 後者は、ストリーム \fIfp\fP から次のパスワードエントリを読み込む。
55 .PP
56 \fIpasswd\fP 構造体は、\fI<pwd.h>\fP で以下のように定義されている:
57 .sp
58 .in +4n
59 .nf
60 struct passwd {
61     char    *pw_name;      /* ユーザ名 */
62     char    *pw_passwd;    /* ユーザのパスワード */
63     uid_t    pw_uid;       /* ユーザ ID */
64     gid_t    pw_gid;       /* グループ ID */
65     char    *pw_gecos;     /* ユーザ情報 */
66     char    *pw_dir;       /* ホームディレクトリ */
67     char    *pw_shell;     /* シェルプログラム */
68 };
69 .fi
70 .in
71 .PP
72 この構造体のフィールドの詳細は \fBpasswd\fP(5)  を参照のこと。
73
74 リエントラントでない関数は静的な格納領域へのポインタを返す。 この静的な格納領域には、更にユーザ名・パスワード・gecos フィールド・
75 ホームディレクトリ・シェルへのポインタが含まれる。 ここで説明されているリエントラント版の関数は、
76 呼び出し側から提供されるバッファにユーザ名など全てを返す。 最初の引き数として \fIstruct passwd\fP を保持できるバッファ \fIpwbuf\fP
77 がある。 次にその他の文字列を保持できるサイズ \fIbuflen\fP のバッファ \fIbuf\fP がある。 これらの関数の結果 (ストリームから読み込まれた
78 \fIstruct passwd\fP) は、 提供されたバッファ \fI*pwbuf\fP に格納され、この \fIstruct passwd\fP へのポインタは
79 \fI*pwbufp\fP に返される。
80 .SH 返り値
81 成功した場合、これらの関数は 0 を返し、 \fI*pwbufp\fP は \fIstruct passwd\fP へのポインタとなる。
82 エラーの場合、これらの関数はエラー値を返し、 \fI*pwbufp\fP は NULL になる。
83 .SH エラー
84 .TP 
85 \fBENOENT\fP
86 次のエントリがない。
87 .TP 
88 \fBERANGE\fP
89 十分なバッファ空間が与えられていない。 もっと大きなバッファで再度実行すること。
90 .SH 準拠
91 これらの関数は GNU 拡張であり、POSIX 版の関数 \fBgetpwnam_r\fP(3)  の形式に似せてある。
92 他のシステムでは以下のプロトタイプが使われている。
93 .sp
94 .nf
95 .in +4n
96 struct passwd *
97 getpwent_r(struct passwd *pwd, char *buf, int buflen);
98 .in
99 .fi
100 .sp
101 より良いものでは、以下のようになっている。
102 .sp
103 .nf
104 .in +4n
105 int
106 getpwent_r(struct passwd *pwd, char *buf, int buflen,
107            FILE **pw_fp);
108 .in
109 .fi
110 .SH 注意
111 関数 \fBgetpwent_r\fP()  は本当のリエントラントではない。 なぜなら、ストリームの読み込み位置を
112 他の全てのスレッドと共有しているためである。
113 .SH 例
114 .nf
115 #define _GNU_SOURCE
116 #include <pwd.h>
117 #include <stdio.h>
118 #define BUFLEN 4096
119
120 int
121 main(void)
122 {
123     struct passwd pw, *pwp;
124     char buf[BUFLEN];
125     int i;
126
127     setpwent();
128     while (1) {
129         i = getpwent_r(&pw, buf, BUFLEN, &pwp);
130         if (i)
131             break;
132         printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp\->pw_name,
133                pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell);
134     }
135     endpwent();
136     exit(EXIT_SUCCESS);
137 }
138 .fi
139 .\" perhaps add error checking - should use strerror_r
140 .\" #include <errno.h>
141 .\" #include <stdlib.h>
142 .\"         if (i) {
143 .\"               if (i == ENOENT)
144 .\"                     break;
145 .\"               printf("getpwent_r: %s", strerror(i));
146 .\"               exit(EXIT_SUCCESS);
147 .\"         }
148 .SH 関連項目
149 \fBfgetpwent\fP(3), \fBgetpw\fP(3), \fBgetpwent\fP(3), \fBgetpwnam\fP(3),
150 \fBgetpwuid\fP(3), \fBputpwent\fP(3), \fBpasswd\fP(5)