Blame nss/nss_fgetent_r.c

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