SD: seek and write seems not working!

Hi guys,
I'm doing a simple opening, seeking and writing operation into the SD file but the result is always appending the content instead of writing at the seek position.

Am I wrong?

File theFile= SD.open(fileName, FILE_WRITE);
if (!theFile) return false;
theFile.seek(0x3FF00);
theFile.write(myByte);
theFile.close();
return true;

I've dumped the position() before and after the seek operation and the "pointer" move corrcty from the size() of the fiel to the given address (0x3FF00) but myByte is written at the location size() + 1...

What do you mean by size() ?

Is myByte really a byte or char?

Just a byte (uint8_t)!

Found the problem: if I open the file with the macro FILE_WRITE it includes O_APPEND and that means that the write will always appended to the end.
I've just opened the file with (O_READ | O_WRITE) and it works fine.

Make sense or maybe a bug in the library?

Markino76:
I've just opened the file with (O_READ | O_WRITE) and it works fine.

What library did you use here? I've used file_write to initialise a log file in a sketch on a device that has been working superbly for over two years. A while back I updated my IDE to the latest verison, and updated some code in the sketch that ONLY changed some of the text that I display on the TFT, no changes to any of the file reading/writing code.

Since then only one of my file.seek instances does not go to the correct position in the file, but places the byte I need to put in there right at the end of the file.

I'm very confused - seems like the other instances of file.seek is working fine apart from this one.

Markino76:
Just a byte (uint8_t)!

Found the problem: if I open the file with the macro FILE_WRITE it includes O_APPEND and that means that the write will always appended to the end.
I've just opened the file with (O_READ | O_WRITE) and it works fine.

Make sense or maybe a bug in the library?

Hi i have the same problem. Can u please explain more about how u solve the problem and give
Code example.? Where and how to used o_write
I tried it in the sketch code instead of FILE_WRITE and it cant openning the file. Please help me

Where and how to used o_write
I tried it in the sketch code instead of FILE_WRITE and it cant openning the file. Please help me

SD.h contains the following
Code: [Select]
#define FILE_WRITE (O_READ | O_WRITE | O_CREAT | O_APPEND)

The O_APPEND forces the write to the end of the file, even though you use file.seek() and try to write at a location.

Use O_RDWR as the mode (This is the same as O_READ|O_WRITE)

Pay attention to capitalization.

//myFile = SD.open ("testing.txt", FILE_WRITE);
  myFile = SD.open ("testing.txt", O_RDWR);