Blame nss/nss_fgetent_r.c

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