.\" 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 Sun Aug 8 00:53:40 JST 2004 .\" by Yuichi SATO .\" .TH GETPWENT_R 3 2015\-01\-22 GNU "Linux Programmer's Manual" .SH 名前 getpwent_r, fgetpwent_r \- パスワードファイルのエントリーを リエントラントで取り出す .SH 書式 .nf \fB#include \fP .sp \fBint getpwent_r(struct passwd *\fP\fIpwbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP .br \fB size_t \fP\fIbuflen\fP\fB, struct passwd **\fP\fIpwbufp\fP\fB);\fP .sp \fBint fgetpwent_r(FILE *\fP\fIstream\fP\fB, struct passwd *\fP\fIpwbuf\fP\fB, char *\fP\fIbuf\fP\fB,\fP .br \fB size_t \fP\fIbuflen\fP\fB, struct passwd **\fP\fIpwbufp\fP\fB);\fP .fi .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp \fBgetpwent_r\fP(), _BSD_SOURCE || _SVID_SOURCE .br \fBfgetpwent_r\fP(): _SVID_SOURCE .SH 説明 関数 \fBgetpwent_r\fP() と \fBfgetpwent_r\fP() は \fBgetpwent\fP(3) と \fBfgetpwent\fP(3) のリエントラント (reentrant) 版である。 前者は、 \fBsetpwent\fP(3) によって初期化されたストリームから、次のパスワードエントリーを読み込む。 後者は、 \fIstream\fP から次のパスワードエントリーを読み込む。 .PP \fIpasswd\fP 構造体は、\fI\fP で以下のように定義されている: .sp .in +4n .nf struct passwd { char *pw_name; /* ユーザー名 */ char *pw_passwd; /* ユーザーのパスワード */ uid_t pw_uid; /* ユーザー ID */ gid_t pw_gid; /* グループ ID */ char *pw_gecos; /* ユーザー情報 */ char *pw_dir; /* ホームディレクトリ */ char *pw_shell; /* シェルプログラム */ }; .fi .in .PP この構造体のフィールドの詳細は \fBpasswd\fP(5) を参照のこと。 リエントラントでない関数は静的な格納領域へのポインターを返す。 この静的な格納領域には、更にユーザー名・パスワード・gecos フィールド・ ホームディレクトリ・シェルへのポインターが含まれる。 ここで説明されているリエントラント版の関数は、 呼び出し側から提供されるバッファーにユーザー名など全てを返す。 最初の引き数として \fIstruct passwd\fP を保持できるバッファー \fIpwbuf\fP がある。 次にその他の文字列を保持できるサイズ \fIbuflen\fP のバッファー \fIbuf\fP がある。 これらの関数の結果 (ストリームから読み込まれた \fIstruct passwd\fP) は、 提供されたバッファー \fI*pwbuf\fP に格納され、この \fIstruct passwd\fP へのポインターは \fI*pwbufp\fP に返される。 .SH 返り値 成功した場合、これらの関数は 0 を返し、 \fI*pwbufp\fP は \fIstruct passwd\fP へのポインターとなる。 エラーの場合、これらの関数はエラー値を返し、 \fI*pwbufp\fP は NULL になる。 .SH エラー .TP \fBENOENT\fP 次のエントリーがない。 .TP \fBERANGE\fP 十分なバッファー空間が与えられていない。 もっと大きなバッファーで再度実行すること。 .SH 準拠 これらの関数は GNU 拡張であり、POSIX 版の関数 \fBgetpwnam_r\fP(3) の形式に似せてある。 他のシステムでは以下のプロトタイプが使われている。 .sp .nf .in +4n struct passwd * getpwent_r(struct passwd *pwd, char *buf, int buflen); .in .fi .sp より良いものでは、以下のようになっている。 .sp .nf .in +4n int getpwent_r(struct passwd *pwd, char *buf, int buflen, FILE **pw_fp); .in .fi .SH 注意 関数 \fBgetpwent_r\fP() は本当のリエントラントではない。 なぜなら、ストリームの読み込み位置を 他の全てのスレッドと共有しているためである。 .SH 例 .nf #define _GNU_SOURCE #include #include #define BUFLEN 4096 int main(void) { struct passwd pw, *pwp; char buf[BUFLEN]; int i; setpwent(); while (1) { i = getpwent_r(&pw, buf, BUFLEN, &pwp); if (i) break; printf("%s (%d)\etHOME %s\etSHELL %s\en", pwp\->pw_name, pwp\->pw_uid, pwp\->pw_dir, pwp\->pw_shell); } endpwent(); exit(EXIT_SUCCESS); } .fi .\" perhaps add error checking - should use strerror_r .\" #include .\" #include .\" if (i) { .\" if (i == ENOENT) .\" break; .\" printf("getpwent_r: %s", strerror(i)); .\" exit(EXIT_SUCCESS); .\" } .SH 関連項目 \fBfgetpwent\fP(3), \fBgetpw\fP(3), \fBgetpwent\fP(3), \fBgetpwnam\fP(3), \fBgetpwuid\fP(3), \fBputpwent\fP(3), \fBpasswd\fP(5) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。