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