title: ftell/fseek fail when near end of file
body: <p>Reading a text file (which happens to be a PDS Member FB 80)</p>
  <pre><code>hFile = fopen(filename,&quot;r&quot;);
  </code></pre>
  <p>and have reached up to the point in the file where there is only an empty line left.</p>
  <pre><code>FilePos = ftell(hFile);
  </code></pre>
  <p>Then read the last line, which only contains a <code>'\n'</code> character.</p>
  <pre><code>fseek(hFile, FilePos, SEEK_SET);
  </code></pre>
  <p>fails with:-</p>
  <pre><code>errno=(27) EDC5027I The position specified to fseek() was invalid.
  </code></pre>
  <p>The position specified to <code>fseek()</code> was returned by <code>ftell()</code> a few lines earlier. It has the value 841 in the specific error case I have seen. Checking through the debugger, this is also the value returned by <code>ftell</code> a few lines earlier. It has not been corrupted.</p>
  <p>The same code works at other positions in the file, and only fails at the point where there is a single empty line left to read when the position is remembered.</p>
  <p>My understanding of how <code>ftell</code>/<code>fseek</code> should work is succinctly captured by another <a href="https://stackoverflow.com/questions/12119132/ftello-fseeko-vs-fgetpos-fsetpos">answer on SO</a>.</p>
  <blockquote>
  <p>The value returned from ftell on a text stream has no predictable relationship to the number of characters you have read so far. The only thing you can rely on is that you can use it subsequently as the offset argument to fseek or fseeko to move back to the same file position.</p>
  </blockquote>
  <p>It would seem that I cannot rely on the one thing I should be able to rely on.</p>
  <p>My questions is, why does <code>fseek</code> fail in this way?</p>