summaryrefslogtreecommitdiffstats
path: root/libc-bottom-half/sources/__wasilibc_tell.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc-bottom-half/sources/__wasilibc_tell.c')
-rw-r--r--libc-bottom-half/sources/__wasilibc_tell.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libc-bottom-half/sources/__wasilibc_tell.c b/libc-bottom-half/sources/__wasilibc_tell.c
new file mode 100644
index 0000000..358d0ca
--- /dev/null
+++ b/libc-bottom-half/sources/__wasilibc_tell.c
@@ -0,0 +1,14 @@
+#include <wasi/api.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;
+}