We could take the lock and still avoid UB with an early return. On Fri, Feb 24, 2023, 09:17 NRK wrote: > On Fri, Feb 24, 2023 at 09:07:41AM -0500, Rich Felker wrote: > > stdio functions are required (by POSIX) to behave as if they take a > > mutex on the FILE. If fread with a length of zero makes forward > > progress when another thread holds the lock, this is non-conforming. > > OK, I see. Wasn't aware of that. > > On a sidenote, if I'm reading the right function (libio/iofread.c) then > glibc is taking the lock _after_ they do the size check. > > if (bytes_requested == 0) > return 0; > _IO_acquire_lock (fp); > /* ... */ > > - NRK >