OSDN Git Service

(split) LDP: draft snapshot generated from latest ja.po files.
[linuxjm/LDP_man-pages.git] / draft / man3 / getgrent_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 GETGRENT_R 3 2010\-10\-21 GNU "Linux Programmer's Manual"
29 .SH 名前
30 getgrent_r, fgetgrent_r \- グループファイルエントリをリエントラント (reentrant) に取り出す
31 .SH 書式
32 .nf
33 \fB#include <grp.h>\fP
34 .sp
35 \fBint getgrent_r(struct group *\fP\fIgbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
36 .br
37 \fB               size_t \fP\fIbuflen\fP\fB, struct group **\fP\fIgbufp\fP\fB);\fP
38 .sp
39 \fBint fgetgrent_r(FILE *\fP\fIfp\fP\fB, struct group *\fP\fIgbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
40 .br
41 \fB                size_t \fP\fIbuflen\fP\fB, struct group **\fP\fIgbufp\fP\fB);\fP
42 .fi
43 .sp
44 .in -4n
45 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
46 .in
47 .sp
48 .\" FIXME . The FTM requirements seem inconsistent here.  File a glibc bug?
49 \fBgetgrent_r\fP(): _GNU_SOURCE
50 .br
51 \fBfgetgrent_r\fP(): _SVID_SOURCE
52 .SH 説明
53 関数 \fBgetgrent_r\fP()  と \fBfgetgrent_r\fP()  は \fBgetgrent\fP(3)  と \fBfgetgrent\fP(3)
54 のリエントラント版である。 前者は、 \fBsetgrent\fP(3)  によって初期化されたストリームから、次のグループファイルのエントリを読み込む。
55 後者は、ストリーム \fIfp\fP から次のグループファイルのエントリを読み込む。
56 .PP
57 \fIgroup\fP 構造体は \fI<grp.h>\fP で以下のように定義されている:
58 .sp
59 .in +4n
60 .nf
61 struct group {
62     char    *gr_name;     /* グループ名 */
63     char    *gr_passwd;   /* グループパスワード */
64     gid_t    gr_gid;      /* グループ ID */
65     char   **gr_mem;      /* グループメンバ */
66 };
67 .fi
68 .in
69 .PP
70 この構造体のフィールドの詳細は \fBgroup\fP(5)  を参照のこと。
71 .PP
72 リエントラントでない関数は静的な格納領域へのポインタを返す。 この静的な格納領域には、更にグループ名・パスワード・ メンバへのポインタが含まれる。
73 ここで説明されているリエントラントな関数は、 呼び出し側から提供されるバッファにグループ名など全てを返す。 最初の引き数として \fIstruct
74 group\fP を保持できるバッファ \fIgbuf\fP がある。 次にその他の文字列を保持できるサイズ \fIbuflen\fP のバッファ \fIbuf\fP
75 がある。 これらの関数の結果 (ストリームから読み込まれた \fIstruct group\fP) は、 提供されたバッファ \fI*gbuf\fP
76 に格納され、この \fIstruct group\fP へのポインタは \fI*gbufp\fP に返される。
77 .SH 返り値
78 成功した場合、これらの関数は 0 を返し、 *\fIgbufp\fP は \fIstruct group\fP へのポインタとなる。
79 エラーの場合、これらの関数はエラー値を返し、 *\fIgbufp\fP は NULL になる。
80 .SH エラー
81 .TP 
82 \fBENOENT\fP
83 次のエントリがない。
84 .TP 
85 \fBERANGE\fP
86 十分なバッファ空間が与えられていない。 もっと大きなバッファで再度実行すること。
87 .SH 準拠
88 これらの関数は GNU 拡張であり、POSIX 版の関数 \fBgetpwnam_r\fP(3)  の形式に似せてある。
89 他のシステムでは以下のプロトタイプが使われている。
90 .sp
91 .nf
92 .in +4n
93 struct group *getgrent_r(struct group *grp, char *buf,
94                          int buflen);
95 .in
96 .fi
97 .sp
98 より良いものでは、以下のようになっている。
99 .sp
100 .nf
101 .in +4n
102 int getgrent_r(struct group *grp, char *buf, int buflen,
103                FILE **gr_fp);
104 .in
105 .fi
106 .SH 注意
107 関数 \fBgetgrent_r\fP()  は本当のリエントラントではない。 なぜなら、ストリームの読み込み位置を
108 他の全てのスレッドと共有しているためである。
109 .SH 例
110 .nf
111 #define _GNU_SOURCE
112 #include <grp.h>
113 #include <stdio.h>
114 #include <stdlib.h>
115 #define BUFLEN 4096
116
117 int
118 main(void)
119 {
120     struct group grp, *grpp;
121     char buf[BUFLEN];
122     int i;
123
124     setgrent();
125     while (1) {
126         i = getgrent_r(&grp, buf, BUFLEN, &grpp);
127         if (i)
128             break;
129         printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid);
130         for (i = 0; ; i++) {
131             if (grpp\->gr_mem[i] == NULL)
132                 break;
133             printf(" %s", grpp\->gr_mem[i]);
134         }
135         printf("\en");
136     }
137     endgrent();
138     exit(EXIT_SUCCESS);
139 }
140 .fi
141 .\" perhaps add error checking - should use strerror_r
142 .\" #include <errno.h>
143 .\" #include <stdlib.h>
144 .\"         if (i) {
145 .\"               if (i == ENOENT)
146 .\"                     break;
147 .\"               printf("getgrent_r: %s", strerror(i));
148 .\"               exit(EXIT_FAILURE);
149 .\"         }
150 .SH 関連項目
151 \fBfgetgrent\fP(3), \fBgetgrent\fP(3), \fBgetgrgid\fP(3), \fBgetgrnam\fP(3),
152 \fBputgrent\fP(3), \fBgroup\fP(5)