POSIX does not say anything about the contents of the array in case of a read error with fgets.
ISO C17 says "the array contents are indeterminate" and N2861 says "the members of the array have unspecified values". In both cases, this is a bit unintuitive concerning s[n-1], as one may get a value that would never be possible in absence of error. So it would be interesting to know whether POSIX follows ISO C or not (note that allowing all contents that would be possible in absence of error would not conflict with ISO C). For instance: char s[2]; s[1] = 0; fgets (s, 2, f); The question is whether one may have s[1] != 0 after fgets is called. -- Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)