Blame nss/nss_fgetent_r.c

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