Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6334

Why is data written to a file opened with O_APPEND flag, always written at the end, even with `lseek`?

$
0
0

I have been given a programming assignment:

Write a program that opens an existing file for writing with the O_APPEND flag, and then seeks to the beginning of the file before writing some data. Where does the data appear in the file? Why?

What I have come up with is:

main() {    int fd = open("test.txt", O_WRONLY | O_APPEND);    lseek(fd, 0, SEEK_SET);    write(fd, "abc", 3);    close(fd);}

Upon trying the above, I have found that the data is always written at the end of the file. Why is that? Is it because I have indicated O_APPEND?


Viewing all articles
Browse latest Browse all 6334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>