Go Down

Topic: What's the deal with FILE_READ and FILE_WRITE? (Read 338 times) previous topic - next topic

jimLee

Sep 18, 2019, 11:31 am Last Edit: Sep 18, 2019, 11:31 am by jimLee
I have a library that does all sorts of things and it only uses FILE_WRITE. Seems to be able to read and write no problem.

I'm working on this new piece of code and if I open with FILE_WRITE.. It only lets me write. If I try reading I get 0 bytes bytes read. If I open it with FILE_READ then it works. It also works if I just omit the READ WRITE thing all together.

What's the rules here? The reference documentation seems a little spotty for this stuff.

Thanks!

-jim lee
PNW Ardiuno & Maker club
1012 9Th Street, Anacortes, WA 98221 (Around the back of building)

Juraj

https://github.com/arduino-libraries/SD/blob/659ee9e3500c7742ceee7920646262cd32bf65e7/src/SD.h#L23

wildbill

If you open a file for write, it's going to append data to the file, so the current position in the file is the end. If you try to read from the file at that point, there's nothing more to read, as you observe.

Juraj

If you open a file for write, it's going to append data to the file, so the current position in the file is the end. If you try to read from the file at that point, there's nothing more to read, as you observe.
then this explains some things
https://github.com/arduino-libraries/SD/commit/38cd35bb3ef6d31afbfbdafde372b0ffdf03849c#diff-a9c18581d236ab799038a90026216672

many years FILE_WRITE define was without O_APPEND

jimLee

https://github.com/arduino-libraries/SD/blob/659ee9e3500c7742ceee7920646262cd32bf65e7/src/SD.h#L23
Quote
// Note that currently only one file can be open at a time.
I thought that was fixed a long time ago?

-jim lee
PNW Ardiuno & Maker club
1012 9Th Street, Anacortes, WA 98221 (Around the back of building)

Go Up