fpurge: Make it work with non fd based FILEs

Streams opened with for example open_memstream(3) will have no associated
file descriptor, and fileno(3) will fail.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
This commit is contained in:
Duncan Overbruck 2022-01-25 20:32:30 +01:00 committed by Guillem Jover
parent 091097e062
commit ba3c46b30f

View File

@ -32,7 +32,7 @@
int
fpurge(FILE *fp)
{
if (fp == NULL || fileno(fp) < 0) {
if (fp == NULL) {
errno = EBADF;
return EOF;
}