OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / draft / 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 2015\-01\-22 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\fIstream\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 後者は、 \fIstream\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 };
75 .fi
76 .in
77 .PP
78 この構造体のフィールドの詳細は \fBgroup\fP(5)  を参照のこと。
79 .PP
80 リエントラントでない関数は静的な格納領域へのポインターを返す。 この静的な格納領域には、更にグループ名・パスワード・ メンバへのポインターが含まれる。
81 ここで説明されているリエントラントな関数は、 呼び出し側から提供されるバッファーにグループ名など全てを返す。 最初の引き数として \fIstruct
82 group\fP を保持できるバッファー \fIgbuf\fP がある。 次にその他の文字列を保持できるサイズ \fIbuflen\fP のバッファー \fIbuf\fP
83 がある。 これらの関数の結果 (ストリームから読み込まれた \fIstruct group\fP) は、 提供されたバッファー \fI*gbuf\fP
84 に格納され、この \fIstruct group\fP へのポインターは \fI*gbufp\fP に返される。
85 .SH 返り値
86 成功した場合、これらの関数は 0 を返し、 *\fIgbufp\fP は \fIstruct group\fP へのポインターとなる。
87 エラーの場合、これらの関数はエラー値を返し、 *\fIgbufp\fP は NULL になる。
88 .SH エラー
89 .TP 
90 \fBENOENT\fP
91 次のエントリーがない。
92 .TP 
93 \fBERANGE\fP
94 十分なバッファー空間が与えられていない。 もっと大きなバッファーで再度実行すること。
95 .SH 準拠
96 これらの関数は GNU 拡張であり、POSIX 版の関数 \fBgetpwnam_r\fP(3)  の形式に似せてある。
97 他のシステムでは以下のプロトタイプが使われている。
98 .sp
99 .nf
100 .in +4n
101 struct group *getgrent_r(struct group *grp, char *buf,
102                          int buflen);
103 .in
104 .fi
105 .sp
106 より良いものでは、以下のようになっている。
107 .sp
108 .nf
109 .in +4n
110 int getgrent_r(struct group *grp, char *buf, int buflen,
111                FILE **gr_fp);
112 .in
113 .fi
114 .SH 注意
115 関数 \fBgetgrent_r\fP()  は本当のリエントラントではない。 なぜなら、ストリームの読み込み位置を
116 他の全てのスレッドと共有しているためである。
117 .SH 例
118 .nf
119 #define _GNU_SOURCE
120 #include <grp.h>
121 #include <stdio.h>
122 #include <stdlib.h>
123 #define BUFLEN 4096
124
125 int
126 main(void)
127 {
128     struct group grp, *grpp;
129     char buf[BUFLEN];
130     int i;
131
132     setgrent();
133     while (1) {
134         i = getgrent_r(&grp, buf, BUFLEN, &grpp);
135         if (i)
136             break;
137         printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid);
138         for (i = 0; ; i++) {
139             if (grpp\->gr_mem[i] == NULL)
140                 break;
141             printf(" %s", grpp\->gr_mem[i]);
142         }
143         printf("\en");
144     }
145     endgrent();
146     exit(EXIT_SUCCESS);
147 }
148 .fi
149 .\" perhaps add error checking - should use strerror_r
150 .\" #include <errno.h>
151 .\" #include <stdlib.h>
152 .\"         if (i) {
153 .\"               if (i == ENOENT)
154 .\"                     break;
155 .\"               printf("getgrent_r: %s", strerror(i));
156 .\"               exit(EXIT_FAILURE);
157 .\"         }
158 .SH 関連項目
159 \fBfgetgrent\fP(3), \fBgetgrent\fP(3), \fBgetgrgid\fP(3), \fBgetgrnam\fP(3),
160 \fBputgrent\fP(3), \fBgroup\fP(5)
161 .SH この文書について
162 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
163 である。プロジェクトの説明とバグ報告に関する情報は
164 http://www.kernel.org/doc/man\-pages/ に書かれている。