]> git.proxmox.com Git - wasi-libc.git/blame - libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c
Wasi snapshot preview1 (#140)
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / unistd / unlinkat.c
CommitLineData
320054e8
DG
1// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2//
3// SPDX-License-Identifier: BSD-2-Clause
4
5#include <common/errno.h>
6
446cb3f1 7#include <wasi/api.h>
320054e8
DG
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
17int 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 }
382b944a 33 return __wasilibc_unlinkat(fd, path);
320054e8
DG
34#endif
35}