OSDN Git Service

223eebeb6fedbf70750fd4f58520f34021d83d2f
[linuxjm/LDP_man-pages.git] / release / man3 / getgrent_r.3
1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\"
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
13 .\"
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 .\" GNU General Public License for more details.
18 .\"
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
22 .\" %%%LICENSE_END
23 .\"
24 .\"*******************************************************************
25 .\"
26 .\" This file was generated with po4a. Translate the source file.
27 .\"
28 .\"*******************************************************************
29 .\"
30 .\" Japanese Version Copyright (c) 2004 Yuichi SATO
31 .\"         all rights reserved.
32 .\" Translated Thu Jul 29 02:26:07 JST 2004
33 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
34 .\"
35 .TH GETGRENT_R 3 2010\-10\-21 GNU "Linux Programmer's Manual"
36 .SH 名前
37 getgrent_r, fgetgrent_r \- グループファイルエントリをリエントラント (reentrant) に取り出す
38 .SH 書式
39 .nf
40 \fB#include <grp.h>\fP
41 .sp
42 \fBint getgrent_r(struct group *\fP\fIgbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
43 .br
44 \fB               size_t \fP\fIbuflen\fP\fB, struct group **\fP\fIgbufp\fP\fB);\fP
45 .sp
46 \fBint fgetgrent_r(FILE *\fP\fIfp\fP\fB, struct group *\fP\fIgbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
47 .br
48 \fB                size_t \fP\fIbuflen\fP\fB, struct group **\fP\fIgbufp\fP\fB);\fP
49 .fi
50 .sp
51 .in -4n
52 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
53 .in
54 .sp
55 .\" FIXME . The FTM requirements seem inconsistent here.  File a glibc bug?
56 \fBgetgrent_r\fP(): _GNU_SOURCE
57 .br
58 \fBfgetgrent_r\fP(): _SVID_SOURCE
59 .SH 説明
60 関数 \fBgetgrent_r\fP()  と \fBfgetgrent_r\fP()  は \fBgetgrent\fP(3)  と \fBfgetgrent\fP(3)
61 のリエントラント版である。 前者は、 \fBsetgrent\fP(3)  によって初期化されたストリームから、次のグループファイルのエントリを読み込む。
62 後者は、ストリーム \fIfp\fP から次のグループファイルのエントリを読み込む。
63 .PP
64 \fIgroup\fP 構造体は \fI<grp.h>\fP で以下のように定義されている:
65 .sp
66 .in +4n
67 .nf
68 struct group {
69     char    *gr_name;     /* グループ名 */
70     char    *gr_passwd;   /* グループパスワード */
71     gid_t    gr_gid;      /* グループ ID */
72     char   **gr_mem;      /* グループメンバ */
73 };
74 .fi
75 .in
76 .PP
77 この構造体のフィールドの詳細は \fBgroup\fP(5)  を参照のこと。
78 .PP
79 リエントラントでない関数は静的な格納領域へのポインタを返す。 この静的な格納領域には、更にグループ名・パスワード・ メンバへのポインタが含まれる。
80 ここで説明されているリエントラントな関数は、 呼び出し側から提供されるバッファにグループ名など全てを返す。 最初の引き数として \fIstruct
81 group\fP を保持できるバッファ \fIgbuf\fP がある。 次にその他の文字列を保持できるサイズ \fIbuflen\fP のバッファ \fIbuf\fP
82 がある。 これらの関数の結果 (ストリームから読み込まれた \fIstruct group\fP) は、 提供されたバッファ \fI*gbuf\fP
83 に格納され、この \fIstruct group\fP へのポインタは \fI*gbufp\fP に返される。
84 .SH 返り値
85 成功した場合、これらの関数は 0 を返し、 *\fIgbufp\fP は \fIstruct group\fP へのポインタとなる。
86 エラーの場合、これらの関数はエラー値を返し、 *\fIgbufp\fP は NULL になる。
87 .SH エラー
88 .TP 
89 \fBENOENT\fP
90 次のエントリがない。
91 .TP 
92 \fBERANGE\fP
93 十分なバッファ空間が与えられていない。 もっと大きなバッファで再度実行すること。
94 .SH 準拠
95 これらの関数は GNU 拡張であり、POSIX 版の関数 \fBgetpwnam_r\fP(3)  の形式に似せてある。
96 他のシステムでは以下のプロトタイプが使われている。
97 .sp
98 .nf
99 .in +4n
100 struct group *getgrent_r(struct group *grp, char *buf,
101                          int buflen);
102 .in
103 .fi
104 .sp
105 より良いものでは、以下のようになっている。
106 .sp
107 .nf
108 .in +4n
109 int getgrent_r(struct group *grp, char *buf, int buflen,
110                FILE **gr_fp);
111 .in
112 .fi
113 .SH 注意
114 関数 \fBgetgrent_r\fP()  は本当のリエントラントではない。 なぜなら、ストリームの読み込み位置を
115 他の全てのスレッドと共有しているためである。
116 .SH 例
117 .nf
118 #define _GNU_SOURCE
119 #include <grp.h>
120 #include <stdio.h>
121 #include <stdlib.h>
122 #define BUFLEN 4096
123
124 int
125 main(void)
126 {
127     struct group grp, *grpp;
128     char buf[BUFLEN];
129     int i;
130
131     setgrent();
132     while (1) {
133         i = getgrent_r(&grp, buf, BUFLEN, &grpp);
134         if (i)
135             break;
136         printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid);
137         for (i = 0; ; i++) {
138             if (grpp\->gr_mem[i] == NULL)
139                 break;
140             printf(" %s", grpp\->gr_mem[i]);
141         }
142         printf("\en");
143     }
144     endgrent();
145     exit(EXIT_SUCCESS);
146 }
147 .fi
148 .\" perhaps add error checking - should use strerror_r
149 .\" #include <errno.h>
150 .\" #include <stdlib.h>
151 .\"         if (i) {
152 .\"               if (i == ENOENT)
153 .\"                     break;
154 .\"               printf("getgrent_r: %s", strerror(i));
155 .\"               exit(EXIT_FAILURE);
156 .\"         }
157 .SH 関連項目
158 \fBfgetgrent\fP(3), \fBgetgrent\fP(3), \fBgetgrgid\fP(3), \fBgetgrnam\fP(3),
159 \fBputgrent\fP(3), \fBgroup\fP(5)
160 .SH この文書について
161 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部
162 である。プロジェクトの説明とバグ報告に関する情報は
163 http://www.kernel.org/doc/man\-pages/ に書かれている。