I am working with Teensy 4.1 with teensyduino SD(fat) library, I can navigate folders, load, save and delete files, but one thing has me stumped.
I could be doing something wrong, but if I try to overwrite a file with new data, the file grows by 4k, and next time I open it, it still has the original data in the first 4k. If I delete the file from the SD before I re-save it, then it works as expected.
Maybe I am not properly understanding what O_TRUNC is supposed to do.
"O_TRUNC - If the file exists and is a regular file, and the file is successfully opened and is not read only, its length shall be truncated to 0."
so I am doing something wrong, or it is not truncating the file as expected.
etc (serial prints are for debugging, and will be removed)
I could be doing something wrong, but if I try to overwrite a file with new data, the file grows by 4k, and next time I open it, it still has the original data in the first 4k. If I delete the file from the SD before I re-save it, then it works as expected.
Maybe I am not properly understanding what O_TRUNC is supposed to do.
"O_TRUNC - If the file exists and is a regular file, and the file is successfully opened and is not read only, its length shall be truncated to 0."
so I am doing something wrong, or it is not truncating the file as expected.
Code:
File newFile = SD.open(fullname, O_WRONLY | O_CREAT | O_TRUNC);//
for (int i = 0; i < coreBytes; i ++) { //coreBytes = 4096
newFile.write(coreBlock[i]); //coreBlock has "coreBytes" bytes
}
Serial.println("end of coreblock");
if (coreBlock[4095] > 0) { //how many paths to save
Serial.print("Saving ");
Serial.print(coreBlock[4095]);
Serial.println(" paths");