Back to index

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

Go to the source code of this file.

Defines

#define BUFLEN_SPWD   1024

Functions

 __libc_lock_define_initialized (static, lock)
struct spwdsgetspent (const char *string)

Define Documentation

#define BUFLEN_SPWD   1024

Definition at line 26 of file sgetspent.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;
}

Here is the call graph for this function:

struct spwd* sgetspent ( const char *  string) [read]

Definition at line 33 of file sgetspent.c.

{
  static char *buffer;
  static size_t buffer_size;
  static struct spwd resbuf;
  struct spwd *result;
  int save;

  /* 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
        && __sgetspent_r (string, &resbuf, buffer, buffer_size, &result) != 0
        && errno == 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;
    }

  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: