]>
Commit | Line | Data |
---|---|---|
320054e8 DG |
1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ |
2 | // | |
3 | // SPDX-License-Identifier: BSD-2-Clause | |
4 | ||
5 | #include <assert.h> | |
446cb3f1 | 6 | #include <wasi/api.h> |
320054e8 DG |
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 | ||
79a9b408 | 14 | #ifdef __wasilibc_unmodified_upstream // Provide an __lseek entry point |
320054e8 | 15 | off_t lseek(int fildes, off_t offset, int whence) { |
cf366c06 | 16 | #else |
79a9b408 | 17 | off_t __lseek(int fildes, off_t offset, int whence) { |
cf366c06 | 18 | #endif |
320054e8 DG |
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 | } | |
79a9b408 DG |
28 | |
29 | #ifdef __wasilibc_unmodified_upstream // Provide an __lseek entry point | |
30 | #else | |
31 | extern __typeof(__lseek) lseek __attribute__((weak, alias("__lseek"))); | |
32 | #endif |