implement file.size for spiffs (#1516)

Another bug squashed!
This commit is contained in:
Arnim Läuger 2016-10-03 03:32:48 +02:00 committed by Philip Gladstone
parent d96d7f237f
commit a86fb74c34
2 changed files with 13 additions and 2 deletions

View File

@ -85,7 +85,7 @@ inline sint32_t vfs_flush( int fd ) {
// Returns: File size
inline uint32_t vfs_size( int fd ) {
vfs_file *f = (vfs_file *)fd;
return f && f->fns->size ? f->fns->size( f ) : 0;
return f ? f->fns->size( f ) : 0;
}
// vfs_ferrno - get file system specific errno

View File

@ -243,6 +243,7 @@ static sint32_t myspiffs_vfs_lseek( const struct vfs_file *fd, sint32_t off, int
static sint32_t myspiffs_vfs_eof( const struct vfs_file *fd );
static sint32_t myspiffs_vfs_tell( const struct vfs_file *fd );
static sint32_t myspiffs_vfs_flush( const struct vfs_file *fd );
static uint32_t myspiffs_vfs_size( const struct vfs_file *fd );
static sint32_t myspiffs_vfs_ferrno( const struct vfs_file *fd );
static sint32_t myspiffs_vfs_closedir( const struct vfs_dir *dd );
@ -295,7 +296,7 @@ static vfs_file_fns myspiffs_file_fns = {
.eof = myspiffs_vfs_eof,
.tell = myspiffs_vfs_tell,
.flush = myspiffs_vfs_flush,
.size = NULL,
.size = myspiffs_vfs_size,
.ferrno = myspiffs_vfs_ferrno
};
@ -477,6 +478,16 @@ static sint32_t myspiffs_vfs_flush( const struct vfs_file *fd ) {
return SPIFFS_fflush( &fs, fh ) >= 0 ? VFS_RES_OK : VFS_RES_ERR;
}
static uint32_t myspiffs_vfs_size( const struct vfs_file *fd ) {
GET_FILE_FH(fd);
int32_t curpos = SPIFFS_tell( &fs, fh );
int32_t size = SPIFFS_lseek( &fs, fh, 0, SPIFFS_SEEK_END );
(void) SPIFFS_lseek( &fs, fh, curpos, SPIFFS_SEEK_SET );
return size;
}
static sint32_t myspiffs_vfs_ferrno( const struct vfs_file *fd ) {
return SPIFFS_errno( &fs );
}