fread()
was originally part of the C standard library, libc
, defined in <stdio.h>
. The C++ standard library makes the same fread()
available through the C library wrapper <cstdio>
.
read()
has no such wrapper (perhaps because it would clash with istream
's version) but you can still call it using the C library. You're correct that read()
came from the POSIX specific extension <unistd.h>
and is not part of the standard library, but it has since been implemented quite broadly and often distributed with libc
.
You're also correct that read()
will set errno
on failure and one of those errors might be EINTR
. And on the other hand when fread()
fails, there is no way to find out what error occurred, so technically you're also correct that EINTR
occurrences are hidden from the user in that case. Indeed, how fread()
handles any platform specific details is up to the implementation. But it would be a stretch to say that this pattern applies to "all C++ standard library functions" - you'd really have to check case by case.
If you want to write "properly functioning" code that runs on every platform, then don't use the POSIX extensions. Stick to fread()
and friends, and accept the fact that generalisation across platforms means you might not be able to get platform specific details like error numbers. Since the possible errors are platform specific, there's no generic way to know if you should try again.
More details on the differences between read()
and fread()
are here.