mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-13 14:50:17 +00:00
Update from main branch.
This commit is contained in:
parent
bc6f3d5a19
commit
531a23d909
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991, 1996, 1997, 1999 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -19,22 +19,28 @@
|
||||
#include <errno.h>
|
||||
#include <bits/libc-lock.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/* We need to protect the dynamic buffer handling. */
|
||||
__libc_lock_define_initialized (static, lock);
|
||||
|
||||
static char *buffer;
|
||||
|
||||
/* Read one entry from the given stream. */
|
||||
struct passwd *
|
||||
fgetpwent (FILE *stream)
|
||||
{
|
||||
static char *buffer;
|
||||
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);
|
||||
|
||||
@ -46,8 +52,8 @@ fgetpwent (FILE *stream)
|
||||
}
|
||||
|
||||
while (buffer != NULL
|
||||
&& __fgetpwent_r (stream, &resbuf, buffer, buffer_size, &result) != 0
|
||||
&& errno == ERANGE)
|
||||
&& (__fgetpwent_r (stream, &resbuf, buffer, buffer_size, &result)
|
||||
== ERANGE))
|
||||
{
|
||||
char *new_buf;
|
||||
buffer_size += NSS_BUFLEN_PASSWD;
|
||||
@ -61,6 +67,10 @@ fgetpwent (FILE *stream)
|
||||
__set_errno (save);
|
||||
}
|
||||
buffer = new_buf;
|
||||
|
||||
/* Reset the stream. */
|
||||
if (fsetpos (stream, &pos) != 0)
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
if (buffer == NULL)
|
||||
@ -73,3 +83,14 @@ fgetpwent (FILE *stream)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Free all resources if necessary. */
|
||||
static void __attribute__ ((unused))
|
||||
free_mem (void)
|
||||
{
|
||||
if (buffer != NULL)
|
||||
free (buffer);
|
||||
}
|
||||
|
||||
text_set_element (__libc_subfreeres, free_mem);
|
||||
|
Loading…
Reference in New Issue
Block a user