What in it requires non-portable C?
Can you provide a portable version?
There's no C language construct that has, as it's standard-defined
semantics, the retrieval of a byte of data from an external device. Any
code you write that has that effect must necessarily be relying upon
something implementation-specific.
Are you thinking of implementing fgetc() by calling some other C
standard library functions? For example:
int fgetc(FILE *stream)
{
char c;
if(fread(&c, 1, 1, stream) != 1)
return EOF;
else
return c;
}
The problem with that approach is that fread() is defined as calling
fgetc(), which would cause infinite recursion. Because of the as-if
rule, fread() doesn't have to actually call fgetc(), but it does at
least have to produce the same effects as if it actually had called
fgetc(). All you've done is pass the issue on to fread(). Sooner or
later, somewhere along the way, there has to be a function that is part
of, or called by C standard library functions, which actually reads one
or more bytes of data from a data storage device without calling any
other functions (except possibly OS-specific functions). So how do you
do that in portable C (which cannot call OS-specific functions)?
The same is true of any other C standard library function that reads one
or more bytes of input from a stream - they all ultimately trace their
required behavior back to fgetc().