looks like OpenBSD is missing this patch from FreeBSD? llvm libc++ hit this (a test worked on other OSes, including FreeBSD-based macOS) but failed on OpenBSD-based Android. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=127335 was the original FreeBSD bug report. POSIX seems to explicitly require this behavior (https://pubs.opengroup.org/onlinepubs/9699919799/functions/fwrite.html: "The fwrite() function shall return the number of elements successfully written, which may be less than nitems if a write error is encountered. If size or nitems is 0, fwrite() shall return 0 and the state of the stream remains unchanged. Otherwise, if a write error occurs, the error indicator for the stream shall be set, and errno shall be set to indicate the error.").
i'm assuming, given that there's already a patch in FreeBSD and it would make more sense to reference that, that there's no point in me sending a "new" patch :-) ~/freebsd$ git show 0cab1fd2369c9 commit 0cab1fd2369c938361ed93befa9191632ef91e2d Author: David Schultz <d...@freebsd.org> Date: Thu Jan 8 06:38:06 2009 +0000 Set the error indicator on an attempt to write to a read-only stream. PR: 127335 MFC after: 2 weeks diff --git a/lib/libc/stdio/wsetup.c b/lib/libc/stdio/wsetup.c index a5da23f003ec..37bfc58bc360 100644 --- a/lib/libc/stdio/wsetup.c +++ b/lib/libc/stdio/wsetup.c @@ -60,6 +60,7 @@ __swsetup(fp) if ((fp->_flags & __SWR) == 0) { if ((fp->_flags & __SRW) == 0) { errno = EBADF; + fp->_flags |= __SERR; return (EOF); } if (fp->_flags & __SRD) { ~/freebsd$