Back to index

glibc  2.9
Defines | Functions
fgetspent.c File Reference
#include <errno.h>
#include <bits/libc-lock.h>
#include <shadow.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define BUFLEN_SPWD   1024

Functions

 __libc_lock_define_initialized (static, lock)
 libc_freeres_ptr (static char *buffer)
struct spwdfgetspent (FILE *stream)

Define Documentation

#define BUFLEN_SPWD   1024

Definition at line 27 of file fgetspent.c.


Function Documentation

__libc_lock_define_initialized ( static  ,
lock   
)

Definition at line 34 of file getnetgrent_r.c.

{
  /* Remember the first service_entry, it's always the same.  */
  static bool startp_initialized;
  static service_user *startp;
  int no_more;

  if (!startp_initialized)
    {
      /* Executing this more than once at the same time must yield the
        same result every time.  So we need no locking.  */
      no_more = __nss_netgroup_lookup (nipp, "setnetgrent", fctp);
      startp = no_more ? (service_user *) -1 : *nipp;
      PTR_MANGLE (startp);
      atomic_write_barrier ();
      startp_initialized = true;
    }
  else
    {
      service_user *nip = startp;
      PTR_DEMANGLE (nip);
      if (nip == (service_user *) -1)
       /* No services at all.  */
       return 1;

      /* Reset to the beginning of the service list.  */
      *nipp = nip;
      /* Look up the first function.  */
      no_more = __nss_lookup (nipp, "setnetgrent", NULL, fctp);
    }
  return no_more;
}
struct spwd* fgetspent ( FILE stream) [read]

Definition at line 36 of file fgetspent.c.

{
  static size_t buffer_size;
  static struct spwd resbuf;
  fpos_t pos;
  struct spwd *result;
  int save;

  if (fgetpos (stream, &pos) != 0)
    return NULL;

  /* Get lock.  */
  __libc_lock_lock (lock);

  /* Allocate buffer if not yet available.  */
  if (buffer == NULL)
    {
      buffer_size = BUFLEN_SPWD;
      buffer = malloc (buffer_size);
    }

  while (buffer != NULL
        && (__fgetspent_r (stream, &resbuf, buffer, buffer_size, &result)
            == ERANGE))
    {
      char *new_buf;
      buffer_size += BUFLEN_SPWD;
      new_buf = realloc (buffer, buffer_size);
      if (new_buf == NULL)
       {
         /* We are out of memory.  Free the current buffer so that the
            process gets a chance for a normal termination.  */
         save = errno;
         free (buffer);
         __set_errno (save);
       }
      buffer = new_buf;

      /* Reset the stream.  */
      if (fsetpos (stream, &pos) != 0)
       buffer = NULL;
    }

  if (buffer == NULL)
    result = NULL;

  /* Release lock.  Preserve error value.  */
  save = errno;
  __libc_lock_unlock (lock);
  __set_errno (save);

  return result;
}

Here is the call graph for this function:

libc_freeres_ptr ( static char *  buffer)