title: Does EOF set errno?
body: <p>I always struggle with return values of system calls - they are just so inconsistent!
  Normally I check if they are NULL or -1 and then call <code>perror</code>. However, for <code>fgets</code>, the man page says:</p>
  
  <blockquote>
    <p><code>gets()</code> and <code>fgets()</code> return s on success, and <code>NULL</code> on error or when end of file occurs while no characters have been read.</p>
  </blockquote>
  
  <p>which means the return value <code>NULL</code> is not necessarily an error - it can also be EOF. Is errno set when the end of file is reached? Can I still call <code>perror</code> in this case?</p>
  
  <p>If not, what is the common way to tell if the call returned an error versus EOF.  I want to use <code>perror</code> with NULL string for errors and a custom string for EOF.</p>