Blame support/xgetline.c

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