diff --git a/libc/include/stdio.h b/libc/include/stdio.h index 644bf9b8..613c54cf 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -3,6 +3,7 @@ #include #include +#include #define SEEK_SET 0 #define SEEK_CUR 1 @@ -29,7 +30,7 @@ extern "C" FILE *fopen(const char *filename, const char *mode); size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); - int fseek(FILE *stream, long offset, int whence); + off_t fseek(FILE *stream, long offset, int whence); long ftell(FILE *stream); int fclose(FILE *fp); int fflush(FILE *stream); diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h index 80471f25..6dbd35c9 100644 --- a/libc/include/sys/stat.h +++ b/libc/include/sys/stat.h @@ -4,7 +4,7 @@ typedef unsigned int _dev_t; typedef unsigned short _ino_t; typedef unsigned short _mode_t; -typedef int _off_t; +typedef long _off_t; #define dev_t _dev_t #define ino_t _ino_t diff --git a/libc/src/std/io/file.c b/libc/src/std/io/file.c index fb5478c2..4706ba5f 100644 --- a/libc/src/std/io/file.c +++ b/libc/src/std/io/file.c @@ -35,22 +35,13 @@ int fclose(FILE *fp) return syscall1(_FileClose, (uint64_t)KP); } -int fseek(FILE *stream, long offset, int whence) +off_t fseek(FILE *stream, long offset, int whence) { - switch (whence) - { - case SEEK_SET: - stream->offset = offset; - break; - case SEEK_CUR: - break; - case SEEK_END: - // stream->offset = syscall1(_FileLength, (uint64_t)File->KernelPrivate) + offset; - break; - default: + off_t new_offset = syscall3(_FileSeek, stream->KernelPrivate, offset, whence); + if (IsSyscallError(new_offset)) return -1; - } - return stream->offset; + stream->offset = new_offset; + return new_offset; } long ftell(FILE *stream)