Skip to content

Commit

Permalink
Merge pull request #122 from sensslen/patch-2
Browse files Browse the repository at this point in the history
Fix #120 - seek virgin file
  • Loading branch information
pellepl authored Dec 14, 2016
2 parents 21fe570 + 19dd301 commit 24682b4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/spiffs_hydrogen.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,16 +577,18 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
spiffs_fflush_cache(fs, fh);
#endif

s32_t fileSize = fd->size == SPIFFS_UNDEFINED_LEN ? 0 : fd->size;

switch (whence) {
case SPIFFS_SEEK_CUR:
offs = fd->fdoffset+offs;
break;
case SPIFFS_SEEK_END:
offs = (fd->size == SPIFFS_UNDEFINED_LEN ? 0 : fd->size) + offs;
offs = fileSize + offs;
break;
}

if ((offs > (s32_t)fd->size) && (SPIFFS_UNDEFINED_LEN != fd->size)) {
if ((offs > fileSize)) {
res = SPIFFS_ERR_END_OF_OBJECT;
}
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
Expand Down

0 comments on commit 24682b4

Please # to comment.