diff --git a/components/spiffs/include/spiffs/esp_spiffs.h b/components/spiffs/include/spiffs/esp_spiffs.h index 2e3beb2f1..bf314caff 100644 --- a/components/spiffs/include/spiffs/esp_spiffs.h +++ b/components/spiffs/include/spiffs/esp_spiffs.h @@ -26,6 +26,7 @@ #define __ESP_SPIFFS_H__ #include "spiffs/spiffs.h" +#include #ifdef __cplusplus extern "C" { @@ -77,6 +78,15 @@ void esp_spiffs_deinit(u8_t format); * @} */ +int _spiffs_open_r(struct _reent *r, const char *filename, int flags, int mode); +_ssize_t _spiffs_read_r(struct _reent *r, int fd, void *buf, size_t len); +_ssize_t _spiffs_write_r(struct _reent *r, int fd, void *buf, size_t len); +_off_t _spiffs_lseek_r(struct _reent *r, int fd, _off_t where, int whence); +int _spiffs_close_r(struct _reent *r, int fd); +int _spiffs_rename_r(struct _reent *r, const char *from, const char *to); +int _spiffs_unlink_r(struct _reent *r, const char *filename); +int _spiffs_fstat_r(struct _reent *r, int fd, struct stat *s); + #ifdef __cplusplus } #endif diff --git a/components/spiffs/library/esp_spiffs.c b/components/spiffs/library/esp_spiffs.c index d7abae76f..a1da407ff 100644 --- a/components/spiffs/library/esp_spiffs.c +++ b/components/spiffs/library/esp_spiffs.c @@ -212,7 +212,7 @@ _ssize_t _spiffs_read_r(struct _reent *r, int fd, void *buf, size_t len) res = SPIFFS_read(&fs, fd - NUM_SYS_FD, buf, len); } - return res; + return SPIFFS_errno(&fs) == SPIFFS_ERR_END_OF_OBJECT ? 0 : res; } _ssize_t _spiffs_write_r(struct _reent *r, int fd, void *buf, size_t len) @@ -234,10 +234,22 @@ _off_t _spiffs_lseek_r(struct _reent *r, int fd, _off_t where, int whence) if (fd < NUM_SYS_FD) { res = -1; } else { + if (whence == SEEK_SET) { + whence = SPIFFS_SEEK_SET; + } else if (whence == SEEK_CUR) { + whence = SPIFFS_SEEK_CUR; + } else if (whence == SEEK_END) { + whence = SPIFFS_SEEK_END; + } + res = SPIFFS_lseek(&fs, fd - NUM_SYS_FD, where, whence); + + if (res < 0) { + printf("lseek failed: %d\n", res); + } } - return res; + return res < 0 ? -1 : res; } int _spiffs_close_r(struct _reent *r, int fd)