diff --git a/lib/libfile.c b/lib/libfile.c index 83c6399..0052e78 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -510,6 +510,24 @@ if (!pos) return fd; + if (mode & (O_WRONLY | O_RDWR)) { + struct stat s; + + ret = fstat(fd, &s); + if (ret) { + perror("fstat"); + return ret; + } + + if (s.st_size < pos) { + ret = ftruncate(fd, pos); + if (ret) { + perror("ftruncate"); + return ret; + } + } + } + ret = lseek(fd, pos, SEEK_SET); if (ret == -1) { perror("lseek");