diff options
| author | Fan Deng <enetor@gmail.com> | 2017-10-18 10:54:54 -0700 |
|---|---|---|
| committer | Fan Deng <enetor@gmail.com> | 2017-10-18 10:54:54 -0700 |
| commit | d8218c9442655f8bdebb912483d425dded654bfd (patch) | |
| tree | 0b56d87e7a61e40d0eb74a3a07f188d2ade16cf5 /src/ext4.c | |
| parent | cc66c4021879f44ff267298c4a666ae8d78d9e43 (diff) | |
Use int64_t as offset to ext4_fseek.
This change makes it possible to fseek backwards in fseek.
Tested:
make test_all
Diffstat (limited to 'src/ext4.c')
| -rw-r--r-- | src/ext4.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -2016,23 +2016,25 @@ Finish: return r; } -int ext4_fseek(ext4_file *file, uint64_t offset, uint32_t origin) +int ext4_fseek(ext4_file *file, int64_t offset, uint32_t origin) { switch (origin) { case SEEK_SET: - if (offset > file->fsize) + if (offset < 0 || (uint64_t)offset > file->fsize) return EINVAL; file->fpos = offset; return EOK; case SEEK_CUR: - if ((offset + file->fpos) > file->fsize) + if ((offset < 0 && (uint64_t)(-offset) > file->fpos) || + (offset > 0 && + (uint64_t)offset > (file->fsize - file->fpos))) return EINVAL; file->fpos += offset; return EOK; case SEEK_END: - if (offset > file->fsize) + if (offset < 0 || (uint64_t)offset > file->fsize) return EINVAL; file->fpos = file->fsize - offset; |
