File: getpwent_r.3

package info (click to toggle)
manpages-ja 0.5.0.0.20210215%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 28,568 kB
  • sloc: perl: 161; makefile: 58
file content (161 lines) | stat: -rw-r--r-- 6,393 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
.\" 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
.\" <http://www.gnu.org/licenses/>.
.\" %%%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 <ysato444@yahoo.co.jp>
.\"
.TH GETPWENT_R 3 2015\-01\-22 GNU "Linux Programmer's Manual"
.SH 名前
getpwent_r, fgetpwent_r \- パスワードファイルのエントリーを リエントラントで取り出す
.SH 書式
.nf
\fB#include <pwd.h>\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<pwd.h>\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 <pwd.h>
#include <stdio.h>
#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 <errno.h>
.\" #include <stdlib.h>
.\"         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/ に書かれている。