Arduino Forum

Using Arduino => Storage => Topic started by: jimLee on Sep 18, 2019, 11:31 am

Title: What's the deal with FILE_READ and FILE_WRITE?
Post by: jimLee on Sep 18, 2019, 11:31 am
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
Title: Re: What's the deal with FILE_READ and FILE_WRITE?
Post by: Juraj on Sep 18, 2019, 11:42 am
https://github.com/arduino-libraries/SD/blob/659ee9e3500c7742ceee7920646262cd32bf65e7/src/SD.h#L23
Title: Re: What's the deal with FILE_READ and FILE_WRITE?
Post by: wildbill on Sep 18, 2019, 04:09 pm
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.
Title: Re: What's the deal with FILE_READ and FILE_WRITE?
Post by: Juraj on Sep 18, 2019, 04:34 pm
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
Title: Re: What's the deal with FILE_READ and FILE_WRITE?
Post by: jimLee on Sep 18, 2019, 11:22 pm
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