Make sure to NUL-terminate the string on end-of-file (and error)