getpwent

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

getpwent, setpwent, endpwent - パスワードファイルのエントリーの取得  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <sys/types.h>
#include <pwd.h>

struct passwd *getpwent(void);
void setpwent(void);
void endpwent(void);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

getpwent(), setpwent(), endpwent():


    _XOPEN_SOURCE >= 500
        || /* glibc >= 2.19: */ _DEFAULT_SOURCE
        || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
 

説明

getpwent() 関数は、パスワードデータベースから取得したエントリーを 要素毎に分解し、各要素を格納した構造体へのポインターを返す (パスワードデータベースの例: ローカルのパスワードファイル /etc/passwd, NIS, LDAP)。 getpwent() は、最初に呼び出された時は最初のエントリーを返し、それ以降は 呼び出される毎に次のエントリーを返す。

setpwent() 関数を使うと、パスワードデータベースの先頭に戻る。

endpwent() 関数は、全ての処理が終わった後にパスワード データベースをクローズする。

passwd 構造体は、<pwd.h> で以下のように定義されている:

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;      /* シェルプログラム */
};

この構造体のフィールドの詳細は passwd(5) を参照のこと。  

返り値

The getpwent() function returns a pointer to a passwd structure, or NULL if there are no more entries or an error occurred. If an error occurs, errno is set to indicate the error. If one wants to check errno after the call, it should be set to zero before the call.

返り値は静的な領域を指しており、その後の getpwent(), getpwnam(3), getpwuid(3) の呼び出しで上書きされるかもしれない。 (返されたポインターを free(3) に渡さないこと。)  

エラー

EINTR
シグナルが捕捉された。signal(7) 参照。
EIO
I/O エラー。
EMFILE
オープンされたファイルディスクリプター数がプロセス毎の上限に達している。
ENFILE
オープンされたファイルの総数がシステム全体の上限に達している。
ENOMEM
passwd 構造体に割り当てるメモリーが十分なかった。
ERANGE
与えられたバッファー空間が不十分である。
 

ファイル

/etc/passwd
ローカルのパスワードデータベースファイル
 

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
getpwent() Thread safety MT-Unsafe race:pwent race:pwentbuf locale
setpwent(), endpwent() Thread safety MT-Unsafe race:pwent locale

In the above table, pwent in race:pwent signifies that if any of the functions setpwent(), getpwent(), or endpwent() are used in parallel in different threads of a program, then data races could occur.  

バージョン

The pw_gecos field is not specified in POSIX, but is present on most implementations.  

標準規格

POSIX.1-2008.  

歴史

POSIX.1-2001, SVr4, 4.3BSD.  

関連項目

fgetpwent(3), getpw(3), getpwent_r(3), getpwnam(3), getpwuid(3), putpwent(3), passwd(5)


 

Index

名前
ライブラリ
書式
説明
返り値
エラー
ファイル
属性
バージョン
標準規格
歴史
関連項目

This document was created by man2html, using the manual pages.