⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getgrent.3

📁 操作系统设计与实现源码
💻 3
字号:
.TH GETGRENT 3.SH NAMEgetgrent, getgrnam, getgrgid, setgrent, endgrent, setgrfile \- group file routines.SH SYNOPSIS.ft B.nf#include <grp.h>struct group *getgrent(void)struct group *getgrnam(const char *\fIname\fP)struct group *getgrgid(gid_t \fIgid\fP)int setgrent(void)void endgrent(void)void setgrfile(const char *\fIfile\fP).fi.ft P.SH DESCRIPTIONThese functions are used to obtain information from the group file.  Theyreturn this information in a.B struct groupas defined by <grp.h>:.PP.nf.ta +4n +6n +15nstruct group {	char	*gr_name;	/* login name */	char	*gr_passwd;	/* encrypted password */	gid_t	gr_gid;	/* numeric group id */	char	**gr_mem;	/* null-terminated list of group members */};.fi.PP.B Getgrent()reads the group file entry by entry..B Getgrnam()scans the entire group file for the group with the given.IR name ..B Getgrgid()looks for the first group with the given.IR gid .The.B setgrent()and.B endgrent()functions are used to open and later close the group file.  With.B setgrfile()one can specify the file to read other than the normal group file.  Thisonly sets the name, the next.B setgrent()call will open the file.  Do not touch the file name while it is active.Use.B setgrfile(NULL)to revert back to the normal group file..PPThe usual way to scan the group file is (error checking omitted):.PP.RS.nf.DTsetgrent();while ((gr = getgrent()) != NULL)	if (appropriate_test(gr)) break;endgrent();.fi.RE.PPThe.B grvariable contains the entry that is wanted if non-NULL.  The.B getgrnam()and.B getgrgid()functions are implemented as in this example, with error checking of course..PP.B Getgrent()calls.B setgrent()if this has not yet been done..B Setgrent()first calls.B endgrent()if the group file is still open.  (Other implementations may simplyrewind the file.).SH FILES.TP 15.B /etc/groupThe group file database..SH "SEE ALSO".BR getgroups (2),.BR initgroups (3),.BR getpwent (3),.BR passwd (5)..SH DIAGNOSTICS.B Setgrent()has the same return value and error codes as the.BR open (2)call it uses to open the group file.  The.BI get xxx ()functions return NULL on end of file, entry not found, or error.  You canset.B errnoto zero before the call and check it after..SH NOTESAll.BI get xxx ()routines return a pointer to static storage that is overwritten in each call..PPOnly.B getgrnam()and.B getgrgid()are defined by \s-2POSIX\s+2.  The.B _MINIX_SOURCEmacro must be defined before including <grp.h> to make the other functionsvisible.  The.B gr_passwdfield is also not defined by \s-2POSIX\s+2, but is always visible.Portable code cannot reliably detect errors by setting.B errnoto zero.  Under Minix it is better to make a.B getgrent()scan if you need to look up several group-id's or names, but portable codehad better use several.B getgrgid()or.B getgrnam()calls.  The.B getgrent()is usually available on other systems, but may be very expensive.  See.BR initgroups (3)if you are after supplementary group id's..SH AUTHORKees J. Bot (kjb@cs.vu.nl)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -