.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu) .\" Modified 2003-11-15 by aeb .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997 HIROFUMI Nishizuka .\" all rights reserved. .\" Translated 1997-12-19, HIROFUMI Nishizuka .\" Updated & Modefied 1999-02-26, Shouichi Saito .\" Updated & Modified 2004-06-05, Yuichi SATO .\" Updated & Modified 2005-09-06, Akihiro MOTOKI .\" Updated 2008-12-24, Akihiro MOTOKI, LDP v3.14 .\" Updated 2012-05-01, Akihiro MOTOKI .\" Updated 2013-07-17, Akihiro MOTOKI .\" Updated 2013-08-16, Akihiro MOTOKI .\" .TH GETGRNAM 3 2013\-07\-22 "" "Linux Programmer's Manual" .SH 名前 getgrnam, getgrnam_r, getgrgid, getgrgid_r \- グループファイルエントリの取り出し .SH 書式 .nf \fB#include \fP \fB#include \fP .sp \fBstruct group *getgrnam(const char *\fP\fIname\fP\fB);\fP .sp \fBstruct group *getgrgid(gid_t \fP\fIgid\fP\fB);\fP .sp \fBint getgrnam_r(const char *\fP\fIname\fP\fB, struct group *\fP\fIgrp\fP\fB,\fP .br \fB char *\fP\fIbuf\fP\fB, size_t \fP\fIbuflen\fP\fB, struct group **\fP\fIresult\fP\fB);\fP .sp \fBint getgrgid_r(gid_t \fP\fIgid\fP\fB, struct group *\fP\fIgrp\fP\fB,\fP .br \fB char *\fP\fIbuf\fP\fB, size_t \fP\fIbuflen\fP\fB, struct group **\fP\fIresult\fP\fB);\fP .fi .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .ad l .in .sp \fBgetgrnam_r\fP(), \fBgetgrgid_r\fP(): .RS 4 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE .RE .ad b .SH 説明 \fBgetgrnam\fP() 関数は、グループ名 \fIname\fP にマッチするグループ・データベースのエントリを 要素毎に分解し、各要素を格納した構造体へのポインタを返す (パスワード・データベースの例: ローカルのグループファイル \fI/etc/group\fP, NIS, LDAP)。 .PP \fBgetgrgid\fP() 関数は、グループ ID \fIuid\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 \fBgetgrnam_r\fP() と \fBgetgrgid_r\fP() 関数は、それぞれ \fBgetgrnam\fP() と \fBgetgrgid\fP() と同じ情報を取得するが、取得した \fIgroup\fP 構造体を \fIgrp\fP が指す領域に格納する。\fIgroup\fP 構造体のメンバーが指す文字列は、 サイズ \fIbuflen\fP のバッファ \fIbuf\fP に格納される。成功した場合 \fI*gbufp\fP には結果へのポインタが格納される。エントリが見つからなかった 場合やエラーが発生した場合には \fI*result\fP には NULL が入る。 .PP 呼び出し sysconf(_SC_GETGR_R_SIZE_MAX) は、 \fIerrno\fP を変更せずに \-1 を返すか、 \fIbuf\fP の初期サイズの推奨値を 返す。(このサイズが小さすぎる場合、呼び出しは \fBERANGE\fP で失敗し、この 場合には呼び出し側はバッファを大きくしてから再度呼び出すことができる。) .SH 返り値 \fBgetgrnam\fP() と \fBgetgrgid\fP() 関数は、 \fIgroup\fP 構造体へのポインタを返す。 マッチするエントリが見つからなかった場合や、 エラーが発生した場合は NULL を返す。 エラーが起こった場合、 \fIerrno\fP が適切に設定される。 呼び出しの後で \fIerrno\fP をチェックしたい場合は、 呼び出しの前に (この値を) 0 に設定しておくべきである。 .LP 返り値は静的な領域を指しており、その後の \fBgetgrent\fP(3), \fBgetgrgid\fP(), \fBgetgrnam\fP() の呼び出しで上書きされるかもしれない。 (返されたポインタを \fBfree\fP(3) に渡さないこと。) .LP 成功すると、 \fBgetgrnam_r\fP() と \fBgetgrgid_r\fP() は 0 を返し、 \fI*result\fP に \fIgrp\fP を設定する。 マッチするグループ・エントリが見つからなかった場合には、 0 を返し、 \fI*result\fP に NULL を設定する。 エラーの場合、エラー番号を返し、 \fI*result\fP に NULL を設定する。 .SH エラー .TP \fB0\fP または \fBENOENT\fP または \fBESRCH\fP または \fBEBADF\fP または \fBEPERM\fP または ... 指定された \fIname\fP または \fIgid\fP が見つからなかった。 .TP \fBEINTR\fP シグナルが捕捉された。 .TP \fBEIO\fP I/O エラー。 .TP \fBEMFILE\fP 呼び出し元プロセスがオープンしているファイル数が すでに上限 (\fBOPEN_MAX\fP) であった。 .TP \fBENFILE\fP システムでオープンされているファイル数がすでに上限であった。 .TP \fBENOMEM\fP .\" not in POSIX .\" to allocate the group structure, or to allocate buffers \fIgroup\fP 構造体を割り当てるためのメモリが不十分。 .TP \fBERANGE\fP 与えられたバッファ空間が不十分である。 .SH ファイル .TP \fI/etc/group\fP ローカルのグループ・データベースファイル .SH 属性 .SS "マルチスレッディング (pthreads(7) 参照)" 関数 \fBgetgrnam\fP() と \fBgetgrgid\fP() はスレッドセーフではない。 .LP 関数 \fBgetgrnam_r\fP() と \fBgetgrgid_r\fP() はスレッドセーフである。 .SH 準拠 SVr4, 4.3BSD, POSIX.1\-2001. .SH 注意 .\" more precisely: .\" AIX 5.1 - gives ESRCH .\" OSF1 4.0g - gives EWOULDBLOCK .\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT .\" glibc since version 2.7 - give 0 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM .\" SunOS 5.8 - gives EBADF .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0 上記の「返り値」以下の記述は POSIX.1\-2001 に拠る。 この標準は「(エントリが) 見つからないこと」をエラーとしていないので、 そのような場合に \fIerrno\fP がどのような値になるかを定めていない。 そのため、エラーを認識することは不可能である。 POSIX に準拠して、エントリが見つからない場合は \fIerrno\fP を変更しないようにすべきである、と主張する人もいるかもしれない。 様々な UNIX 系のシステムで試してみると、そのような場合には 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM といった様々な値が返される。 他の値が返されるかもしれない。 .SH 関連項目 \fBendgrent\fP(3), \fBfgetgrent\fP(3), \fBgetgrent\fP(3), \fBgetpwnam\fP(3), \fBsetgrent\fP(3), \fBgroup\fP(5) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。