.\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl) .\" .\" 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, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. .\" .\" 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 2010-10-21 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O getpwent_r, fgetpwent_r \- get passwd file entry reentrantly getpwent_r, fgetpwent_r \- パスワードファイルのエントリを リエントラントで取り出す .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "int getpwent_r(struct passwd *" pwbuf ", char *" buf , .br .BI " size_t " buflen ", struct passwd **" pwbufp ); .sp .BI "int fgetpwent_r(FILE *" fp ", struct passwd *" pwbuf ", char *" buf , .br .BI " size_t " buflen ", struct passwd **" pwbufp ); .fi .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR getpwent_r (), _BSD_SOURCE || _SVID_SOURCE .br .BR fgetpwent_r (): _SVID_SOURCE .\"O .SH DESCRIPTION .SH 説明 .\"O The functions .\"O .BR getpwent_r () .\"O and .\"O .BR fgetpwent_r () .\"O are the reentrant versions of .\"O .BR getpwent (3) .\"O and .\"O .BR fgetpwent (3). 関数 .BR getpwent_r () と .BR fgetpwent_r () は .BR getpwent (3) と .BR fgetpwent (3) のリエントラント (reentrant) 版である。 .\"O The former reads the next passwd entry from the stream initialized by .\"O .BR setpwent (3). 前者は、 .BR setpwent (3) によって初期化されたストリームから、次のパスワードエントリを読み込む。 .\"O The latter reads the next passwd entry from the stream .\"O .IR fp . 後者は、ストリーム .I fp から次のパスワードエントリを読み込む。 .PP .\"O The \fIpasswd\fP structure is defined in .\"O .I .\"O as follows: \fIpasswd\fP 構造体は .I において以下のように定義されている。 .sp .in +4n .nf struct passwd { .\"O char *pw_name; /* username */ .\"O char *pw_passwd; /* user password */ .\"O uid_t pw_uid; /* user ID */ .\"O gid_t pw_gid; /* group ID */ .\"O char *pw_gecos; /* user information */ .\"O char *pw_dir; /* home directory */ .\"O char *pw_shell; /* shell program */ 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 .\"O For more information about the fields of this structure, see .\"O .BR passwd (5). この構造体のフィールドの詳細は .BR passwd (5) を参照のこと。 .\"O The nonreentrant functions return a pointer to static storage, .\"O where this static storage contains further pointers to user .\"O name, password, gecos field, home directory and shell. リエントラントでない関数は静的な格納領域へのポインタを返す。 この静的な格納領域には、更にユーザ名・パスワード・gecos フィールド・ ホームディレクトリ・シェルへのポインタが含まれる。 .\"O The reentrant functions described here return all of that in .\"O caller-provided buffers. .\"O First of all there is the buffer .\"O .I pwbuf .\"O that can hold a \fIstruct passwd\fP. .\"O And next the buffer .\"O .I buf .\"O of size .\"O .I buflen .\"O that can hold additional strings. ここで説明されているリエントラント版の関数は、 呼び出し側から提供されるバッファにユーザ名など全てを返す。 最初の引き数として \fIstruct passwd\fP を保持できるバッファ .I pwbuf がある。 次にその他の文字列を保持できるサイズ .I buflen のバッファ .I buf がある。 .\"O The result of these functions, the \fIstruct passwd\fP read from the stream, .\"O is stored in the provided buffer .\"O .IR *pwbuf , .\"O and a pointer to this \fIstruct passwd\fP is returned in .\"O .IR *pwbufp . これらの関数の結果 (ストリームから読み込まれた \fIstruct passwd\fP) は、 提供されたバッファ .I *pwbuf に格納され、この \fIstruct passwd\fP へのポインタは .I *pwbufp に返される。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O On success, these functions return 0 and .\"O .I *pwbufp .\"O is a pointer to the \fIstruct passwd\fP. 成功した場合、これらの関数は 0 を返し、 .I *pwbufp は \fIstruct passwd\fP へのポインタとなる。 エラーの場合、これらの関数はエラー値を返し、 .I *pwbufp は NULL になる。 .\"O .SH ERRORS .SH エラー .TP .B ENOENT .\"O No more entries. 次のエントリがない。 .TP .B ERANGE .\"O Insufficient buffer space supplied. .\"O Try again with larger buffer. 十分なバッファ空間が与えられていない。 もっと大きなバッファで再度実行すること。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O These functions are GNU extensions, done in a style resembling .\"O the POSIX version of functions like .\"O .BR getpwnam_r (3). これらの関数は GNU 拡張であり、POSIX 版の関数 .BR getpwnam_r (3) の形式に似せてある。 .\"O Other systems use prototype 他のシステムでは以下のプロトタイプが使われている。 .sp .nf .in +4n struct passwd * getpwent_r(struct passwd *pwd, char *buf, int buflen); .in .fi .sp .\"O or, better, より良いものでは、以下のようになっている。 .sp .nf .in +4n int getpwent_r(struct passwd *pwd, char *buf, int buflen, FILE **pw_fp); .in .fi .\"O .SH NOTES .SH 注意 .\"O The function .\"O .BR getpwent_r () .\"O is not really reentrant since it shares the reading position .\"O in the stream with all other threads. 関数 .BR getpwent_r () は本当のリエントラントではない。 なぜなら、ストリームの読み込み位置を 他の全てのスレッドと共有しているためである。 .\"O .SH EXAMPLE .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 .\"O .\" perhaps add error checking - should use strerror_r .\" たぶんエラーチェックを追加して、strerror_r を使うべきだろう。 .\" #include .\" #include .\" if (i) { .\" if (i == ENOENT) .\" break; .\" printf("getpwent_r: %s", strerror(i)); .\" exit(EXIT_SUCCESS); .\" } .\"O .SH "SEE ALSO" .SH 関連項目 .BR fgetpwent (3), .BR getpw (3), .BR getpwent (3), .BR getpwnam (3), .BR getpwuid (3), .BR putpwent (3), .BR passwd (5)