]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c
WASI libc prototype implementation.
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / unistd / unlinkat.c
1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2 //
3 // SPDX-License-Identifier: BSD-2-Clause
4
5 #include <common/errno.h>
6
7 #include <wasi/core.h>
8 #ifdef __wasilibc_unmodified_upstream // unlink
9 #else
10 #include <wasi/libc.h>
11 #endif
12 #include <errno.h>
13 #include <fcntl.h>
14 #include <string.h>
15 #include <unistd.h>
16
17 int unlinkat(int fd, const char *path, int flag) {
18 #ifdef __wasilibc_unmodified_upstream // unlink
19 __wasi_ulflags_t ulflags = 0;
20 if ((flag & AT_REMOVEDIR) != 0)
21 ulflags |= __WASI_UNLINK_REMOVEDIR;
22 __wasi_errno_t error =
23 __wasi_file_unlink(fd, path, strlen(path), ulflags);
24 if (error != 0) {
25 errno = errno_fixup_directory(fd, error);
26 return -1;
27 }
28 return 0;
29 #else
30 if ((flag & AT_REMOVEDIR) != 0) {
31 return __wasilibc_rmdirat(fd, path);
32 }
33 return __wasilibc_rmfileat(fd, path);
34 #endif
35 }