mirror of
https://git.proxmox.com/git/wasi-libc
synced 2025-07-15 05:28:17 +00:00

* Add an entrypoint for calling open that bypasses the varargs. * Add an entrypoint for calling openat that bypasses the varargs.
22 lines
439 B
C
22 lines
439 B
C
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
#include <wasi/libc.h>
|
|
|
|
int truncate(const char *path, off_t length)
|
|
{
|
|
int fd = __wasilibc_open_nomode(path, O_WRONLY | O_CLOEXEC | O_NOCTTY);
|
|
if (fd < 0)
|
|
return -1;
|
|
|
|
int result = ftruncate(fd, length);
|
|
if (result != 0) {
|
|
int save_errno = errno;
|
|
(void)close(fd);
|
|
errno = save_errno;
|
|
return -1;
|
|
}
|
|
|
|
return close(fd);
|
|
}
|