Page 1 of 1

Simple file truncation example?

Posted: Mon Dec 30, 2024 2:35 pm
by JamesBlonde
Hi Everyone,

Maybe I need a coffee...but I cannot truncate a file using FatFS/POSIX or anything I can put my hands on...

Simple example of what I'm trying to achieve (assume file is 100B).

Code: Select all

FILE *f = fopen(file_path, "r+");
fseek(f,-20,SEEK_END);
truncate(f,0);
fflush(f);
f_sync(f);
abort();
Can anyone please show simple example of how to truncate file?

Re: Simple file truncation example?

Posted: Mon Jan 06, 2025 6:58 am
by ESP_rrtandler
Hi JamesBlonde,

Try to evaluate / print return codes of each of the function called in the example. Including initial fopen. Perhaps your trouble is caused by some typo or other trivial cause and the detailed log helps you to focus on the particular operation returning the unexpected result.