Blame support/xgetline.c

Packit Service 38b4f1
/* fopen with error checking.
Packit Service 38b4f1
   Copyright (C) 2020 Free Software Foundation, Inc.
Packit Service 38b4f1
   This file is part of the GNU C Library.
Packit Service 38b4f1
Packit Service 38b4f1
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 38b4f1
   modify it under the terms of the GNU Lesser General Public
Packit Service 38b4f1
   License as published by the Free Software Foundation; either
Packit Service 38b4f1
   version 2.1 of the License, or (at your option) any later version.
Packit Service 38b4f1
Packit Service 38b4f1
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 38b4f1
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 38b4f1
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 38b4f1
   Lesser General Public License for more details.
Packit Service 38b4f1
Packit Service 38b4f1
   You should have received a copy of the GNU Lesser General Public
Packit Service 38b4f1
   License along with the GNU C Library; if not, see
Packit Service 38b4f1
   <https://www.gnu.org/licenses/>.  */
Packit Service 38b4f1
Packit Service 38b4f1
#include <support/xstdio.h>
Packit Service 38b4f1
#include <support/check.h>
Packit Service 38b4f1
#include <errno.h>
Packit Service 38b4f1
Packit Service 38b4f1
ssize_t
Packit Service 38b4f1
xgetline (char **lineptr, size_t *n, FILE *stream)
Packit Service 38b4f1
{
Packit Service 38b4f1
  int old_errno = errno;
Packit Service 38b4f1
  errno = 0;
Packit Service 38b4f1
  size_t ret = getline (lineptr, n, stream);
Packit Service 38b4f1
  if (!feof (stream) && ferror (stream))
Packit Service 38b4f1
    FAIL_EXIT1 ("getline failed: %m");
Packit Service 38b4f1
  errno = old_errno;
Packit Service 38b4f1
  return ret;
Packit Service 38b4f1
}