littlefs icon indicating copy to clipboard operation
littlefs copied to clipboard

Opening file in Read/Write mode and set good file size

Open SadE54 opened this issue 2 years ago • 0 comments

Hi ,

In a project I have to open a file with LFS_O_RDWR | LFS_O_CREAT mode, because at the time os the open function is used, I don't know if I have to write it or only read it (it's mapped to an external can bus file transferprotocol) The problem is that if I'm writing , for example a 5000B sized file, and in another session open this file again and change the content to a 100B size, the final file size will still be 5000B . I guess I have to use LFS_O_TRUNC but if the file is only read , the file size will be set to 0 😫

Is there a scheme I could use to manage such a situation ?

SadE54 avatar May 13 '22 15:05 SadE54