Back to index

glibc  2.9
Classes | Defines | Functions
fgetgrent_r.c File Reference
#include <ctype.h>
#include <errno.h>
#include <grp.h>
#include <stdio.h>
#include <nss/nss_files/files-parse.c>

Go to the source code of this file.

Classes

struct  grent_data

Defines

#define STRUCTURE   group
#define ENTNAME   grent
#define TRAILING_LIST_MEMBER   gr_mem
#define TRAILING_LIST_SEPARATOR_P(c)   ((c) == ',')

Functions

 LINE_PARSER ()

Class Documentation

struct grent_data

Definition at line 35 of file fgetgrent_r.c.


Define Documentation

#define ENTNAME   grent

Definition at line 34 of file fgetgrent_r.c.

#define STRUCTURE   group

Definition at line 33 of file fgetgrent_r.c.

#define TRAILING_LIST_MEMBER   gr_mem

Definition at line 37 of file fgetgrent_r.c.

#define TRAILING_LIST_SEPARATOR_P (   c)    ((c) == ',')

Definition at line 38 of file fgetgrent_r.c.


Function Documentation

Definition at line 41 of file fgetgrent_r.c.

   {
     result->gr_passwd = NULL;
     result->gr_gid = 0;
   }
 else
   {
     STRING_FIELD (result->gr_passwd, ISCOLON, 0);
     if (result->gr_name[0] == '+' || result->gr_name[0] == '-')
       INT_FIELD_MAYBE_NULL (result->gr_gid, ISCOLON, 0, 10, , 0)
     else
       INT_FIELD (result->gr_gid, ISCOLON, 0, 10,)
   }
 )


/* Read one entry from the given stream.  */
int
__fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
              struct group **result)
{
  char *p;
  int parse_result;

  flockfile (stream);
  do
    {
      buffer[buflen - 1] = '\xff';
      p = fgets_unlocked (buffer, buflen, stream);
      if (__builtin_expect (p == NULL, 0) && feof_unlocked (stream))
       {
         funlockfile (stream);
         *result = NULL;
         __set_errno (ENOENT);
         return errno;
       }
      if (__builtin_expect (p == NULL, 0) || buffer[buflen - 1] != '\xff')
       {
         funlockfile (stream);
         *result = NULL;
         __set_errno (ERANGE);
         return errno;
       }

      /* Skip leading blanks.  */
      while (isspace (*p))
       ++p;
    } while (*p == '\0' || *p == '#'      /* Ignore empty and comment lines.  */
            /* Parse the line.  If it is invalid, loop to
              get the next line of the file to parse.  */
            || ! (parse_result = parse_line (p, resbuf,
                                         (void *) buffer, buflen,
                                         &errno)));

  funlockfile (stream);

  if (__builtin_expect (parse_result, 0) == -1)
    {
      /* The parser ran out of space.  */
      *result = NULL;
      return errno;
    }

  *result = resbuf;
  return 0;
}