ironsheep/P2-FLASH-FS

Write should return number of bytes written

totalspectrum opened this issue · 2 comments

Issue being Addressed

The write function returns only a status, and no indication of how many bytes were written.

Enhancement

The write function should probably act like Unix (and Windows) and return the count of bytes actually written, rather than a status of 0 on success. This will allow us to detect things like flash full, and also be more consistent with how other OSes work.

Alternatives

I can work around this in the flexspin VFS layer, but it seems like it might surprise other users as well who are used to POSIX and Windows APIs.

Additional information

No response

Implemented. Appears in v1.3.0 and later

It appears that on failure write() is returning an error code, rather than the number of bytes actually written. It would be nice to know how much we were able to write before the error. The error code can be retrieved with the error() method, but bytes actually written cannot be otherwise determined. (Again, this is the way POSIX and I believe Windows both work.)

A wrinkle is that if no bytes at all are written but there is an error then typically write() should return -1 rather than 0, iirc.