Simple file truncation example?

JamesBlonde
Posts: 5
Joined: Thu Apr 04, 2024 2:29 pm

Simple file truncation example?

Postby JamesBlonde » Mon Dec 30, 2024 2:35 pm

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?

ESP_rrtandler
Posts: 53
Joined: Wed May 31, 2023 6:54 pm

Re: Simple file truncation example?

Postby ESP_rrtandler » Mon Jan 06, 2025 6:58 am

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.

Who is online

Users browsing this forum: Bing [Bot], Bytespider and 1 guest