return the next entry from the group database
#include <grp.h> struct group *getgrent( void );
The getgrent() function returns the next entry from the group database, although no particular order is guaranteed. This function uses a static buffer that's overwritten by each call.
The next entry from the group database. When getgrent() is first called, the group database is opened, and remains open until either a NULL is returned to signify end-of-file, or endgrent() is called.
The getgrent() function uses the following functions, and as a result errno can be set to a valid error for any of these calls:
/* * This program loops, reading a group name from * standard input and checking to see if it is a valid * group. If it is not valid, the entire contents of the * group database are printed. */ #include <stdio.h> #include <grp.h> #include <limits.h> void main() { struct group *gr; char buf[80]; setgrent(); while( gets(buf) != NULL) { if( (gr=getgrnam(buf)) != (struct group *)0) { printf("Valid group is: %s\n",gr->gr_name); } else { setgrent(); while( (gr=getgrent()) != (struct group *)0 ) printf("%s\n",gr->gr_name); } } endgrent(); }
UNIX
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
endgrent(), errno, getgrgid(), getgrnam(), getpwent(), setgrent()