Exemplo n.º 1
0
struct passwd* fgetpwent (FILE* stream)
{
  struct passwd* result;
  int retval = __fgetpwent_r (stream, &passwd, buffer, 1024, &result);
  
  if (retval != 0)
    return NULL;
  return &passwd;
}
Exemplo n.º 2
0
/* Read one entry from the given stream.  */
struct passwd *
fgetpwent (FILE *stream)
{
  static size_t buffer_size;
  static struct passwd resbuf;
  fpos_t pos;
  struct passwd *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 = NSS_BUFLEN_PASSWD;
      buffer = malloc (buffer_size);
    }

  while (buffer != NULL
	 && (__fgetpwent_r (stream, &resbuf, buffer, buffer_size, &result)
	     == ERANGE))
    {
      char *new_buf;
      buffer_size += NSS_BUFLEN_PASSWD;
      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;
}