Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/g/getgrent.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/g/getgrent.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/g/getgrent.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/g/getgrent.html on line 8

getgrent()

Return an entry from the group database

Synopsis:

#include <grp.h>

struct group* getgrent( void );

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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.


Note: The getgrent(), getgrgid(), and getgrnam() function share the same static buffer.

Returns:

The next entry from the group database. When you first call getgrent(), the group database is opened. It remains open until either getgrent() returns NULL to signify end-of-file, or you call endgrent().

Errors:

The getgrent() function uses the following functions, and as a result, errno can be set to an error for any of these calls:

Examples:

/*
 * 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 );
  }

Classification:

POSIX 1003.1 XSI

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread No

See also:

endgrent(), errno, getgrgid(), getgrnam(), getpwent(), getpwent_r(), setgrent()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/g/getgrent.html on line 178

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/g/getgrent.html on line 178