Here's a simple patch that describes ferror(3)'s error conditions. Feel free to
change the wording to be more consistent with OpenBSD conventions; for example,
I wasn't sure whether to use .St when talking about POSIX, since 'IEEE Std
1003.1-2008 ("POSIX.1")' seemed a little long for the main text. It may also
be worth linking to the following functions, which return FILE pointers that
trigger this case:
- open_memstream(3)
- open_wmemstream(3)
- fmemopen(3)
- fropen(3)
- fwopen(3)
- any other ones I'm missing
diff --git lib/libc/stdio/ferror.3 lib/libc/stdio/ferror.3
index 526c07e32a8..159c2163be8 100644
--- lib/libc/stdio/ferror.3
+++ lib/libc/stdio/ferror.3
@@ -76,10 +76,31 @@ The function
examines the argument
.Fa stream
and returns its integer file descriptor.
+If no file descriptor is associated with
+.Fa stream ,
+.Fn fileno
+returns -1.
.Sh ERRORS
-These functions should not fail and do not set the external
+The
+.Fn clearerr ,
+.Fn feof ,
+and
+.Fn ferror
+functions should not fail, and do not set the external
variable
.Va errno .
+.Pp
+The
+.Fn fileno
+function may fail, and return -1, if
+.Fa stream
+is not associated with a file descriptor.
+.Ox
+does not follow the optional POSIX recommendation to set
+.Va errno
+to
+.Er EBADF
+in that case.
.Sh SEE ALSO
.Xr open 2 ,
.Xr stdio 3