]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c
Wasi snapshot preview1 (#140)
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / unistd / linkat.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/api.h>
8 #include <errno.h>
9 #include <fcntl.h>
10 #include <string.h>
11 #include <unistd.h>
12
13 int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag) {
14 // Create lookup properties.
15 #ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
16 __wasi_lookup_t lookup1 = {.fd = fd1, .flags = 0};
17 #else
18 __wasi_lookupflags_t lookup1_flags = 0;
19 #endif
20 if ((flag & AT_SYMLINK_FOLLOW) != 0)
21 #ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
22 lookup1.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
23 #else
24 lookup1_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW;
25 #endif
26
27 // Perform system call.
28 #ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
29 __wasi_errno_t error = __wasi_file_link(lookup1, path1, strlen(path1),
30 #else
31 __wasi_errno_t error = __wasi_path_link(fd1, lookup1_flags, path1, strlen(path1),
32 #endif
33 fd2, path2, strlen(path2));
34 if (error != 0) {
35 errno = errno_fixup_directory(fd1, errno_fixup_directory(fd2, error));
36 return -1;
37 }
38 return 0;
39 }