title: lseek issues
body: <p>I'm having a hard time figuring out why <code>lseek</code> doesn't work properly. Basically all I need to do is take input from the standard input, store it into a file named "log.txt" and let the program stop as the "STOP" word is encountered.</p>
  
  <p>My problem is as I try to run the program I get an lseek error: illegal seek and I don't know why. I thought the issue was the call to lseek but if I substitute <code>lseek(fd, 0, SEEK_END)</code> with <code>lseek(fd, atol(0), SEEK_END)</code> I get a segmentation fault. </p>
  
  <p>I'm just so confused, I don't know how to proceed in order to fix this, I hope you could give your advice.</p>
  
  
  
  <pre><code>int fd;
  char buffer[SIZE];
  int n, cur;
  
  if (fd = open("log.txt", O_RDWR, S_IRWXU|S_IRWXG|S_IRWXO) &lt; 0)
  {
      perror("Error: open");
      return 1;
  }
  
  if ((cur = lseek(fd, 0, SEEK_END)) &lt; 0)
  {
      printf("Offset corrente: %d\n", (int) lseek(fd, SIZE, SEEK_CUR));
      perror("Error: lseek");
      return 2;
  }
  
  while ((n = read(fd, buffer, SIZE)) &gt; 0 &amp;&amp; (strncmp(buffer, "STOP", 4) != 0))
  {
      write(fd, buffer, SIZE);
  }
  </code></pre>