开发者

How to rewrite a particular block of file

开发者 https://www.devze.com 2023-01-04 21:19 出处:网络
I want to rewrite a particular block in a file but its not working for me For example if I want to rewrite to offset 4 of the file I used lseek(fd,4,SEEK_SET) and calle开发者_StackOverflow社区d write

I want to rewrite a particular block in a file but its not working for me

For example if I want to rewrite to offset 4 of the file I used lseek(fd,4,SEEK_SET) and calle开发者_StackOverflow社区d write system call but its writing at the end of the file instead of at offset 4.


Don't use O_APPEND. It will append everything to the end of the file, regardless of your seeking.

Use:

open("file.txt", O_RDWR);

You're assuming the file already exists, so I don't see why you would use O_CREAT.

0

精彩评论

暂无评论...
验证码 换一张
取 消