Merge Changes done for #120 and fix file position setting

This commit is contained in:
sensslen
2016-12-15 08:39:07 +01:00
+5 -3
View File
@@ -577,17 +577,19 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
spiffs_fflush_cache(fs, fh); spiffs_fflush_cache(fs, fh);
#endif #endif
s32_t fileSize = fd->size == SPIFFS_UNDEFINED_LEN ? 0 : fd->size;
switch (whence) { switch (whence) {
case SPIFFS_SEEK_CUR: case SPIFFS_SEEK_CUR:
offs = fd->fdoffset+offs; offs = fd->fdoffset+offs;
break; break;
case SPIFFS_SEEK_END: case SPIFFS_SEEK_END:
offs = (fd->size == SPIFFS_UNDEFINED_LEN ? 0 : fd->size) + offs; offs = fileSize + offs;
break; break;
} }
if ((offs > (s32_t)fd->size) && (SPIFFS_UNDEFINED_LEN != fd->size)) { if ((offs > fileSize)) {
fd->fdoffset = fd->size; fd->fdoffset = fileSize;
res = SPIFFS_ERR_END_OF_OBJECT; res = SPIFFS_ERR_END_OF_OBJECT;
} }
SPIFFS_API_CHECK_RES_UNLOCK(fs, res); SPIFFS_API_CHECK_RES_UNLOCK(fs, res);