title: Why would the read system call stop working halfway through a program?
body: <p>I'm working on an assignment that involves creating files and manipulating characters within them using what the lecturer describes as &quot;File and System I/O calls&quot; in C.</p>
  <p>Specifically, I am using open, creat, read, write, lseek, close, and unlink.</p>
  <p>Without revealing too much and violating academic integrity, essentially the assignment just entails creating files, copying characters between them, changing the characters, etc.</p>
  <p>All of this was going perfectly until a certain point of the program after which read just... Wouldn't work. It doesn't matter what file I am accessing, or what other calls I put before it- for instance, I have tried closing and re-opening a file before trying to read, writing before reading (worked perfectly, put the characters right at the file position the lseek intended), etc.</p>
  <p>I have checked the returns of all previous commands, none are giving errors other than the read, which is giving me errorno 9. Having looked this up, it appears to refer to having an incorrect file descriptor, but this doesn't make sense to me as I can use the same fid for any other command. Using ls -l, I confirmed that I have read and write permission (groups and public do not, if that helps).</p>
  <p>I am at a total loss of where to go troubleshooting from here, any help would be immensely appreciated. Here is the code snippet in question:</p>
  <pre><code>readStatus = lseek(WWWfid,500,0);
  if (readStatus&lt;0) {
      printf(&quot;error with lseek&quot;); 
      return 0;
  }
  /*printf(&quot;Read status: %i\n&quot;, readStatus);/*DEBUG*/
  writeStatus = write(WWWfid, &quot;wtf&quot;, 3);
  if (writeStatus&lt;0) {
      printf(&quot;error with write&quot;);
      return 0;
  }
          
  readStatus = read(WWWfid, buffer, 26);
  int errorNum = errno;
  /*buffer[27] = '\0';*/
  if (readStatus&lt;0) {
      printf(&quot;error with read before loop, error %i\n&quot;, errorNum);
      return 0;
  }
  </code></pre>
  <p>I can likely include more without invoking the wroth of my uni but I'd prefer not to- also seems likely to be irrelevant given that all proceeding code appears to be functioning correctly.
  Thanks for reading, please let me know if you have any insight at all</p>