1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Moving write errors out of return value into separate API methods.

write(), print(), println() now return size_t (and don't use negative values to signal errors).
Print adds writeError() for checking for write errors, clearWriteError() to reset the flag to false, and a protected setWriteError() for signalling errors.

http://code.google.com/p/arduino/issues/detail?id=598
This commit is contained in:
David A. Mellis
2011-08-26 16:08:14 -04:00
parent 929597375b
commit b73cf39d94
23 changed files with 184 additions and 173 deletions

View File

@ -141,7 +141,7 @@ class SdFile : public Print {
* Set writeError to false before calling print() and/or write() and check
* for true after calls to print() and/or write().
*/
bool writeError;
//bool writeError;
/**
* Cancel unbuffered reads for this file.
* See setUnbufferedRead()
@ -283,9 +283,9 @@ class SdFile : public Print {
}
/** \return SdVolume that contains this file. */
SdVolume* volume(void) const {return vol_;}
ssize_t write(uint8_t b);
ssize_t write(const void* buf, uint16_t nbyte);
ssize_t write(const char* str);
size_t write(uint8_t b);
size_t write(const void* buf, uint16_t nbyte);
size_t write(const char* str);
void write_P(PGM_P str);
void writeln_P(PGM_P str);
//------------------------------------------------------------------------------

View File

@ -1121,7 +1121,7 @@ uint8_t SdFile::truncate(uint32_t length) {
* for a read-only file, device is full, a corrupt file system or an I/O error.
*
*/
ssize_t SdFile::write(const void* buf, uint16_t nbyte) {
size_t SdFile::write(const void* buf, uint16_t nbyte) {
// convert void* to uint8_t* - must be before goto statements
const uint8_t* src = reinterpret_cast<const uint8_t*>(buf);
@ -1210,8 +1210,9 @@ ssize_t SdFile::write(const void* buf, uint16_t nbyte) {
writeErrorReturn:
// return for write error
writeError = true;
return -1;
//writeError = true;
setWriteError();
return 0;
}
//------------------------------------------------------------------------------
/**
@ -1219,7 +1220,7 @@ ssize_t SdFile::write(const void* buf, uint16_t nbyte) {
*
* Use SdFile::writeError to check for errors.
*/
ssize_t SdFile::write(uint8_t b) {
size_t SdFile::write(uint8_t b) {
return write(&b, 1);
}
//------------------------------------------------------------------------------
@ -1228,7 +1229,7 @@ ssize_t SdFile::write(uint8_t b) {
*
* Use SdFile::writeError to check for errors.
*/
ssize_t SdFile::write(const char* str) {
size_t SdFile::write(const char* str) {
return write(str, strlen(str));
}
//------------------------------------------------------------------------------