|
Packit Service |
e08a93 |
/* Generic implementation of fget*ent_r.
|
|
Packit Service |
e08a93 |
Copyright (C) 2020 Free Software Foundation, Inc.
|
|
Packit Service |
e08a93 |
This file is part of the GNU C Library.
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
e08a93 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
e08a93 |
License as published by the Free Software Foundation; either
|
|
Packit Service |
e08a93 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
e08a93 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
e08a93 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
e08a93 |
Lesser General Public License for more details.
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
e08a93 |
License along with the GNU C Library; if not, see
|
|
Packit Service |
e08a93 |
<https://www.gnu.org/licenses/>. */
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
#include <errno.h>
|
|
Packit Service |
e08a93 |
#include <nss_files.h>
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
int
|
|
Packit Service |
e08a93 |
__nss_fgetent_r (FILE *fp, void *result, char *buffer, size_t buffer_length,
|
|
Packit Service |
e08a93 |
nss_files_parse_line parser)
|
|
Packit Service |
e08a93 |
{
|
|
Packit Service |
e08a93 |
int ret;
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
_IO_flockfile (fp);
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
while (true)
|
|
Packit Service |
e08a93 |
{
|
|
Packit Service |
e08a93 |
off64_t original_offset;
|
|
Packit Service |
e08a93 |
ret = __nss_readline (fp, buffer, buffer_length, &original_offset);
|
|
Packit Service |
e08a93 |
if (ret == 0)
|
|
Packit Service |
e08a93 |
{
|
|
Packit Service |
e08a93 |
/* Parse the line into *RESULT. */
|
|
Packit Service |
e08a93 |
ret = parser (buffer, result,
|
|
Packit Service |
e08a93 |
(struct parser_data *) buffer, buffer_length, &errno);
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
/* Translate the result code from the parser into an errno
|
|
Packit Service |
e08a93 |
value. Also seeks back to the start of the line if
|
|
Packit Service |
e08a93 |
necessary. */
|
|
Packit Service |
e08a93 |
ret = __nss_parse_line_result (fp, original_offset, ret);
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
if (ret == EINVAL)
|
|
Packit Service |
e08a93 |
/* Skip over malformed lines. */
|
|
Packit Service |
e08a93 |
continue;
|
|
Packit Service |
e08a93 |
}
|
|
Packit Service |
e08a93 |
break;
|
|
Packit Service |
e08a93 |
}
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
_IO_funlockfile (fp);
|
|
Packit Service |
e08a93 |
|
|
Packit Service |
e08a93 |
return ret;
|
|
Packit Service |
e08a93 |
}
|