1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ 2 // 3 // SPDX-License-Identifier: BSD-2-Clause 4 5 #include <wasi/api.h> 6 #include <errno.h> 7 #include <unistd.h> 8 ftruncate(int fildes,off_t length)9int ftruncate(int fildes, off_t length) { 10 if (length < 0) { 11 errno = EINVAL; 12 return -1; 13 } 14 __wasi_filesize_t st_size = length; 15 __wasi_errno_t error = 16 __wasi_fd_filestat_set_size(fildes, st_size); 17 if (error != 0) { 18 errno = error; 19 return -1; 20 } 21 return 0; 22 } 23