.\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl) .\" .\" %%%LICENSE_START(GPLv2+_DOC_FULL) .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, see .\" . .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2004 Yuichi SATO .\" all rights reserved. .\" Translated Thu Jul 29 02:26:07 JST 2004 .\" by Yuichi SATO .\" .TH GETGRENT_R 3 2015\-01\-22 GNU "Linux Programmer's Manual" .SH 名前 getgrent_r, fgetgrent_r \- グループファイルエントリーをリエントラント (reentrant) に取り出す .SH 書式 .nf \fB#include \fP .sp \fBint getgrent_r(struct group *\fP\fIgbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP .br \fB size_t \fP\fIbuflen\fP\fB, struct group **\fP\fIgbufp\fP\fB);\fP .sp \fBint fgetgrent_r(FILE *\fP\fIstream\fP\fB, struct group *\fP\fIgbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP .br \fB size_t \fP\fIbuflen\fP\fB, struct group **\fP\fIgbufp\fP\fB);\fP .fi .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp .\" FIXME . The FTM requirements seem inconsistent here. File a glibc bug? \fBgetgrent_r\fP(): _GNU_SOURCE .br \fBfgetgrent_r\fP(): _SVID_SOURCE .SH 説明 関数 \fBgetgrent_r\fP() と \fBfgetgrent_r\fP() は \fBgetgrent\fP(3) と \fBfgetgrent\fP(3) のリエントラント版である。 前者は、 \fBsetgrent\fP(3) によって初期化されたストリームから、次のグループファイルのエントリーを読み込む。 後者は、 \fIstream\fP から次のグループファイルのエントリーを読み込む。 .PP \fIgroup\fP 構造体は \fI\fP で以下のように定義されている: .sp .in +4n .nf struct group { char *gr_name; /* グループ名 */ char *gr_passwd; /* グループのパスワード */ gid_t gr_gid; /* グループ ID */ char **gr_mem; /* グループのメンバ名へのポインター の配列 (配列はヌルで終端する) */ }; .fi .in .PP この構造体のフィールドの詳細は \fBgroup\fP(5) を参照のこと。 .PP リエントラントでない関数は静的な格納領域へのポインターを返す。 この静的な格納領域には、更にグループ名・パスワード・ メンバへのポインターが含まれる。 ここで説明されているリエントラントな関数は、 呼び出し側から提供されるバッファーにグループ名など全てを返す。 最初の引き数として \fIstruct group\fP を保持できるバッファー \fIgbuf\fP がある。 次にその他の文字列を保持できるサイズ \fIbuflen\fP のバッファー \fIbuf\fP がある。 これらの関数の結果 (ストリームから読み込まれた \fIstruct group\fP) は、 提供されたバッファー \fI*gbuf\fP に格納され、この \fIstruct group\fP へのポインターは \fI*gbufp\fP に返される。 .SH 返り値 成功した場合、これらの関数は 0 を返し、 *\fIgbufp\fP は \fIstruct group\fP へのポインターとなる。 エラーの場合、これらの関数はエラー値を返し、 *\fIgbufp\fP は NULL になる。 .SH エラー .TP \fBENOENT\fP 次のエントリーがない。 .TP \fBERANGE\fP 十分なバッファー空間が与えられていない。 もっと大きなバッファーで再度実行すること。 .SH 準拠 これらの関数は GNU 拡張であり、POSIX 版の関数 \fBgetpwnam_r\fP(3) の形式に似せてある。 他のシステムでは以下のプロトタイプが使われている。 .sp .nf .in +4n struct group *getgrent_r(struct group *grp, char *buf, int buflen); .in .fi .sp より良いものでは、以下のようになっている。 .sp .nf .in +4n int getgrent_r(struct group *grp, char *buf, int buflen, FILE **gr_fp); .in .fi .SH 注意 関数 \fBgetgrent_r\fP() は本当のリエントラントではない。 なぜなら、ストリームの読み込み位置を 他の全てのスレッドと共有しているためである。 .SH 例 .nf #define _GNU_SOURCE #include #include #include #define BUFLEN 4096 int main(void) { struct group grp, *grpp; char buf[BUFLEN]; int i; setgrent(); while (1) { i = getgrent_r(&grp, buf, BUFLEN, &grpp); if (i) break; printf("%s (%d):", grpp\->gr_name, grpp\->gr_gid); for (i = 0; ; i++) { if (grpp\->gr_mem[i] == NULL) break; printf(" %s", grpp\->gr_mem[i]); } printf("\en"); } endgrent(); exit(EXIT_SUCCESS); } .fi .\" perhaps add error checking - should use strerror_r .\" #include .\" #include .\" if (i) { .\" if (i == ENOENT) .\" break; .\" printf("getgrent_r: %s", strerror(i)); .\" exit(EXIT_FAILURE); .\" } .SH 関連項目 \fBfgetgrent\fP(3), \fBgetgrent\fP(3), \fBgetgrgid\fP(3), \fBgetgrnam\fP(3), \fBputgrent\fP(3), \fBgroup\fP(5) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。