__wasilibc_register_preopened_fd
__wasilibc_rmdirat
__wasilibc_rmfileat
+__wasilibc_tell
__wcscoll_l
__wcsftime_l
__wcsxfrm_l
#define logb(x) __tg_real(logb, (x))
#define lrint(x) __tg_real_nocast(lrint, (x))
#define lround(x) __tg_real_nocast(lround, (x))
+#define lseek(fd,offset,whence) ({ off_t __f = (fd); off_t __o = (offset); off_t __w = (whence); __builtin_constant_p((offset)) && __builtin_constant_p((whence)) && __o == 0 && __w == SEEK_CUR ? __wasilibc_tell(__f) : lseek(__f, __o, __w); })
#define lseek64 lseek
#define lstat64 lstat
#define major(x) ((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) ))
__wasi_fd_renumber
__wasi_fd_seek
__wasi_fd_sync
+__wasi_fd_tell
__wasi_fd_write
__wasi_path_create_directory
__wasi_path_filestat_get
static_assert(SEEK_END == __WASI_WHENCE_END, "Value mismatch");
static_assert(SEEK_SET == __WASI_WHENCE_SET, "Value mismatch");
+#ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */
off_t lseek(int fildes, off_t offset, int whence) {
+#else
+off_t (lseek)(int fildes, off_t offset, int whence) {
+#endif
__wasi_filesize_t new_offset;
__wasi_errno_t error =
__wasi_fd_seek(fildes, offset, whence, &new_offset);
#ifndef __wasi_libc_h
#define __wasi_libc_h
+#include <__typedef_off_t.h>
+
#ifdef __cplusplus
extern "C" {
#endif
int __wasilibc_fd_renumber(int fd, int newfd);
int __wasilibc_rmfileat(int fd, const char *path);
int __wasilibc_rmdirat(int fd, const char *path);
+off_t __wasilibc_tell(int fd);
#ifdef __cplusplus
}
--- /dev/null
+#include <wasi/core.h>
+#include <errno.h>
+
+off_t __wasilibc_tell(int fildes) {
+ __wasi_filesize_t offset;
+ __wasi_errno_t error = __wasi_fd_tell(fildes, &offset);
+ if (error != 0) {
+ // lseek returns ESPIPE on when called on a pipe, socket, or fifo,
+ // which on WASI would translate into ENOTCAPABLE.
+ errno = error == ENOTCAPABLE ? ESPIPE : error;
+ return -1;
+ }
+ return offset;
+}
int dup3(int, int, int);
#endif
off_t lseek(int, off_t, int);
+#ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */
+#else
+/*
+ * Optimize lseek in the case where it's just returning the current offset.
+ * This avoids importing `__wasi_fd_seek` altogether in many common cases.
+ */
+
+off_t __wasilibc_tell(int);
+
+#define lseek(fd, offset, whence) \
+ ({ \
+ off_t __f = (fd); \
+ off_t __o = (offset); \
+ off_t __w = (whence); \
+ __builtin_constant_p((offset)) && \
+ __builtin_constant_p((whence)) && \
+ __o == 0 && \
+ __w == SEEK_CUR \
+ ? __wasilibc_tell(__f) \
+ : lseek(__f, __o, __w); \
+ })
+#endif
int fsync(int);
int fdatasync(int);