]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c
a0e41b70867a9e8d653f3197858518bcff65aae2
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / unistd / lseek.c
1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2 //
3 // SPDX-License-Identifier: BSD-2-Clause
4
5 #include <assert.h>
6 #include <wasi/core.h>
7 #include <errno.h>
8 #include <unistd.h>
9
10 static_assert(SEEK_CUR == __WASI_WHENCE_CUR, "Value mismatch");
11 static_assert(SEEK_END == __WASI_WHENCE_END, "Value mismatch");
12 static_assert(SEEK_SET == __WASI_WHENCE_SET, "Value mismatch");
13
14 #ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */
15 off_t lseek(int fildes, off_t offset, int whence) {
16 #else
17 off_t (lseek)(int fildes, off_t offset, int whence) {
18 #endif
19 __wasi_filesize_t new_offset;
20 __wasi_errno_t error =
21 __wasi_fd_seek(fildes, offset, whence, &new_offset);
22 if (error != 0) {
23 errno = error == ENOTCAPABLE ? ESPIPE : error;
24 return -1;
25 }
26 return new_offset;
27 }