Skip to content

feat(spiffs): Make SPIFFS API more POSIX compatible. (GIT8266O-310) #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/spiffs/include/spiffs/esp_spiffs.h
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
#define __ESP_SPIFFS_H__

#include "spiffs/spiffs.h"
#include <fcntl.h>

#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
16 changes: 14 additions & 2 deletions components/spiffs/library/esp_spiffs.c
Original file line number Diff line number Diff line change
@@ -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)