diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
| commit | fc00c656c96528112d05cf0edf8631bd5eaea446 (patch) | |
| tree | a6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/stdio/fseek.c | |
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/stdio/fseek.c')
| -rw-r--r-- | lib/libc/stdio/fseek.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c new file mode 100644 index 00000000..af12cd2c --- /dev/null +++ b/lib/libc/stdio/fseek.c @@ -0,0 +1,28 @@ +#include <unistd.h> +#include <io.h> +#include <stdio.h> +#include <atomic.h> + +int fseek(FILE *stream, long offset, int whence) +{ + if (stream == NULL || stream->fd < 0) + return -1; + + LIBC_LOCK(stream->lock); + + stream->buf_pos = 0; + stream->buf_len = 0; + stream->flags &= ~_IO_EOF; + + off_t result = lseek(stream->fd, offset, whence); + + LIBC_UNLOCK(stream->lock); + + if (result == (off_t)-1) { + stream->flags |= _IO_ERR; + return -1; + } + + stream->offset = result; + return 0; +} |
