lseek()

If you ever wonder how to use basic open, seek, read/write operations on native file descriptor (in Linux), here's a brief example. It should give general overview on how it's done.
I was actually not quite sure how to lseek() before writing this post myself.

#include <unistd.h>
#include <fcntl.h>


int fd;
int main(){
    fd = open("foo",O_WRONLY | O_CREAT, S_IRWXU);
    lseek(fd, 0, SEEK_END);
    write(fd,"abc\n",4);
    }


See, the offset and whence value can be played around. I can do {SEEK_SET, SEEK_END} to get exactly the same result. :D

Anyway, it's nice to see OR operation on enum values.

0 rants: