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

write(), print(), and println() now return number of bytes written.

The type is long, and negative values indicate errors.  Needs more testing.
http://code.google.com/p/arduino/issues/detail?id=551
This commit is contained in:
David A. Mellis
2011-08-23 19:12:03 -04:00
parent b788ad593f
commit 8059abe581
24 changed files with 290 additions and 174 deletions

View File

@ -58,19 +58,20 @@ boolean File::isDirectory(void) {
}
void File::write(uint8_t val) {
if (_file)
_file->write(val);
long File::write(uint8_t val) {
return write(&val, 1);
}
void File::write(const char *str) {
if (_file)
_file->write(str);
long File::write(const char *str) {
return write((const uint8_t *) str, strlen(str));
}
void File::write(const uint8_t *buf, size_t size) {
if (_file)
_file->write(buf, size);
long File::write(const uint8_t *buf, size_t size) {
long t;
if (!_file) return -1;
t = _file->write(buf, size);
if (t < 0) return t - 1;
return t;
}
int File::peek() {

View File

@ -32,9 +32,9 @@ public:
File(SdFile f, char *name); // wraps an underlying SdFile
File(void); // 'empty' constructor
~File(void); // destructor
virtual void write(uint8_t);
virtual void write(const char *str);
virtual void write(const uint8_t *buf, size_t size);
virtual long write(uint8_t);
virtual long write(const char *str);
virtual long write(const uint8_t *buf, size_t size);
virtual int read();
virtual int peek();
virtual int available();

View File

@ -283,9 +283,9 @@ class SdFile : public Print {
}
/** \return SdVolume that contains this file. */
SdVolume* volume(void) const {return vol_;}
void write(uint8_t b);
int16_t write(const void* buf, uint16_t nbyte);
void write(const char* str);
long write(uint8_t b);
long write(const void* buf, uint16_t nbyte);
long 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.
*
*/
int16_t SdFile::write(const void* buf, uint16_t nbyte) {
long 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);
@ -1219,8 +1219,8 @@ int16_t SdFile::write(const void* buf, uint16_t nbyte) {
*
* Use SdFile::writeError to check for errors.
*/
void SdFile::write(uint8_t b) {
write(&b, 1);
long SdFile::write(uint8_t b) {
return write(&b, 1);
}
//------------------------------------------------------------------------------
/**
@ -1228,8 +1228,8 @@ void SdFile::write(uint8_t b) {
*
* Use SdFile::writeError to check for errors.
*/
void SdFile::write(const char* str) {
write(str, strlen(str));
long SdFile::write(const char* str) {
return write(str, strlen(str));
}
//------------------------------------------------------------------------------
/**