While reading the C99 draft ISO/IEC 9899:TC2 WG14/N1124, I stumbled upon some statements that worries me:
Is the string/buffer given to fgets
also guaranteed to be null terminated if fgets
returns NULL
?
§7.19.7.2 states in the description
A null character is written immediately after the last character read into the array.
But under return:
If a read error occurs during the operation, the array contents are indeterminate and a null pointer is returned.
So the last statement implies in my interpretation that this guarantee is not given in any NULL
-returning case.
I'm already about to correct http://en.cppreference.com, since they are using errno
, which fgets
isn't obliged to set. But I'm not sure if I maybe misinterpret this.