[Bug 283014] POSIX issue 7: fileno should be able to fail with EBADF

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 28 Nov 2024 19:27:12 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=283014

Ed Maste <emaste@freebsd.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |emaste@freebsd.org

--- Comment #1 from Ed Maste <emaste@freebsd.org> ---
Perhaps:

diff --git a/lib/libc/stdio/fileno.c b/lib/libc/stdio/fileno.c
index 66502430dc3d..ff317993c0d3 100644
--- a/lib/libc/stdio/fileno.c
+++ b/lib/libc/stdio/fileno.c
@@ -49,6 +49,9 @@ fileno(FILE *fp)
        fd = __sfileno(fp);
        FUNLOCKFILE(fp);

+       if (fd == -1)
+               errno = EBADF;
+
        return (fd);
 }

-- 
You are receiving this mail because:
You are the assignee for the bug.