![]() |
![]() |
![]() |
Return an entry from the group database
#include <grp.h> struct group* getgrent( void );
libc
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 getgrent(), getgrgid(), and getgrnam() function share the same static buffer. |
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 isn't valid, the entire contents of the * group database are printed. */ #include <stdio.h> #include <stdlib.h> #include <grp.h> #include <limits.h> int main( void ) { 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(); return( EXIT_SUCCESS ); }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | No |
endgrent(), errno, getgrgid(), getgrnam(), getpwent(), setgrent()
![]() |
![]() |
![]() |