title: return value of lseek()
body: <p>I got confused about <code>lseek()</code>'s return value(which is new file offset)</p>
  
  <p>I have the text file (Its name is prwtest). Its contents are written to a to z.</p>
  
  <p>And, the code what I wrote is following,</p>
  
  <pre><code>  1 #include &lt;unistd.h&gt;
    2 #include &lt;fcntl.h&gt;
    3 #include &lt;stdlib.h&gt;
    4 #include &lt;stdio.h&gt;
    5 #include &lt;string.h&gt;
    6 
    7 #define BUF 50
    8 
    9 int main(void)
   10 {
   11         char buf1[]="abcdefghijklmnopqrstuvwxyz";
   12         char buf2[BUF];
   13         int fd;
   14         int read_cnt;
   15         off_t cur_offset;
   16 
   17         fd=openat(AT_FDCWD, "prwtest", O_CREAT | O_RDWR | O_APPEND);
   18         cur_offset=lseek(fd, 0, SEEK_CUR);
   19         //pwrite(fd, buf1, strlen(buf1), 0);
   20         //write(fd, buf1, strlen(buf1));
   21         //cur_offset=lseek(fd, 0, SEEK_END);
   22 
   23         printf("current offset of file prwtest: %d \n", cur_offset);
   24 
   25         exit(0);
   26 }
  </code></pre>
  
  <p>On the line number <code>17</code>, I use flag <code>O_APPEND</code>, so the prwtest's current file offset is taken from i-node's current file size. (It's 26).</p>
  
  <p>On the line number <code>18</code>, I use <code>lseek()</code> which is used by SEEK_CUR, and the offset is 0.</p>
  
  <p>But the result value <code>cur_offset</code> is 0. (I assume that it must be 26, because SEEK_CUR indicates current file offset.)
  However, <code>SEEK_END</code> gives me what I thought, <code>cur_offset</code> is 26.</p>
  
  <p>Why the <code>lseek(fd, 0, SEEK_CUR);</code> gives me return value 0, not 26?</p>