summaryrefslogtreecommitdiffstats
path: root/libc-bottom-half/sources/__wasilibc_tell.c
blob: 358d0ca375af7cebde3083baaf62201f239cf274 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}