-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Wrong pos cursor in append mode #9
Comments
That's a good suggestion, but the current behaviour is standard (although not the most intuitive). After append you will most like do one of two things:
If you want to have the pos at the end of the file you can put it there manually with seek: lfs_file_open(&lfs, &file, "file.txt", LFS_O_RDWR | LFS_O_APPEND);
lfs_file_seek(&lfs, &file, 0, SEEK_END); You can see the standard behaviour with a small program on your PC: #include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main() {
int f = open("test.txt", O_WRONLY | O_CREAT);
write(f, "aaaaaaaaaa", 10);
close(f);
printf("created test.txt\n");
f = open("test.txt", O_RDWR | O_APPEND);
int off = lseek(f, 0, SEEK_CUR);
printf("pos after open %d\n", off);
write(f, "aaaaaaaaaa", 10);
off = lseek(f, 0, SEEK_CUR);
printf("pos after write %d\n", off);
close(f);
} output:
more info on the behaviour of the O_APPEND flag: |
Ok then we keep it as the default behavior |
Hi,
When opening a file with append flags, the pos cursor at beginning is 0 but should be the size of the file
I propose to add
The text was updated successfully, but these errors were encountered: