Path: blob/main/system/lib/libc/wasi-helpers.c
6162 views
/*1* Copyright 2019 The Emscripten Authors. All rights reserved.2* Emscripten is available under two separate licenses, the MIT license and the3* University of Illinois/NCSA Open Source License. Both these licenses can be4* found in the LICENSE file.5*/67#include <errno.h>8#include <stdlib.h>9#include <time.h>10#include <wasi/api.h>11#include <wasi/wasi-helpers.h>1213int __wasi_syscall_ret(__wasi_errno_t code) {14if (code == __WASI_ERRNO_SUCCESS) return 0;15// We depend on the fact that wasi codes are identical to our errno codes.16errno = code;17return -1;18}1920int __wasi_fd_is_valid(__wasi_fd_t fd) {21__wasi_fdstat_t statbuf;22int err = __wasi_fd_fdstat_get(fd, &statbuf);23if (err != __WASI_ERRNO_SUCCESS) {24errno = err;25return 0;26}27return 1;28}2930#define NSEC_PER_SEC (1000 * 1000 * 1000)3132struct timespec __wasi_timestamp_to_timespec(__wasi_timestamp_t timestamp) {33return (struct timespec){.tv_sec = timestamp / NSEC_PER_SEC,34.tv_nsec = timestamp % NSEC_PER_SEC};35}363738