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
Packit Service 3c5cac
size_t
Packit Service 38b4f1
xgetline (char **lineptr, size_t *n, FILE *stream)
Packit Service 38b4f1
{
Packit Service 3c5cac
  TEST_VERIFY (!ferror (stream));
Packit Service 3c5cac
  ssize_t ret = getline (lineptr, n, stream);
Packit Service 3c5cac
  if (ferror (stream))
Packit Service 3c5cac
    {
Packit Service 3c5cac
      TEST_VERIFY (ret < 0);
Packit Service 3c5cac
      FAIL_EXIT1 ("getline: %m");
Packit Service 3c5cac
    }
Packit Service 3c5cac
  if (feof (stream))
Packit Service 3c5cac
    {
Packit Service 3c5cac
      TEST_VERIFY (ret <= 0);
Packit Service 3c5cac
      return 0;
Packit Service 3c5cac
    }
Packit Service 3c5cac
  TEST_VERIFY (ret > 0);
Packit Service 38b4f1
  return ret;
Packit Service 38b4f1
}