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
?