Skip to content

Commit 350ea74

Browse files
committed
Split file_unlink into file and directory forms.
Split file_unlink into file_unlink_file and file_unlink_directory. Rather than one function with a flags argument to say which of two things to do, having two functions allows finer-grained import capabilities. Also, standardize the errno choices for the unlink functions, in cases where underlying Unix platforms differ.
1 parent 66069f3 commit 350ea74

4 files changed

Lines changed: 37 additions & 15 deletions

File tree

expected/wasm32-wasi/predefined-macros.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,9 +3552,10 @@
35523552
#define __WASI_RIGHT_FILE_STAT_SET_SIZE (UINT64_C(0x0000000000080000))
35533553
#define __WASI_RIGHT_FILE_STAT_SET_TIMES (UINT64_C(0x0000000000100000))
35543554
#define __WASI_RIGHT_FILE_SYMLINK (UINT64_C(0x0000000001000000))
3555-
#define __WASI_RIGHT_FILE_UNLINK (UINT64_C(0x0000000002000000))
3556-
#define __WASI_RIGHT_POLL_FD_READWRITE (UINT64_C(0x0000000004000000))
3557-
#define __WASI_RIGHT_SOCK_SHUTDOWN (UINT64_C(0x0000000008000000))
3555+
#define __WASI_RIGHT_FILE_UNLINK_DIRECTORY (UINT64_C(0x0000000004000000))
3556+
#define __WASI_RIGHT_FILE_UNLINK_FILE (UINT64_C(0x0000000002000000))
3557+
#define __WASI_RIGHT_POLL_FD_READWRITE (UINT64_C(0x0000000008000000))
3558+
#define __WASI_RIGHT_SOCK_SHUTDOWN (UINT64_C(0x0000000010000000))
35583559
#define __WASI_SHUT_RD (UINT8_C(0x01))
35593560
#define __WASI_SHUT_WR (UINT8_C(0x02))
35603561
#define __WASI_SIGABRT (UINT8_C(6))
@@ -3591,7 +3592,6 @@
35913592
#define __WASI_SOCK_RECV_PEEK (UINT16_C(0x0001))
35923593
#define __WASI_SOCK_RECV_WAITALL (UINT16_C(0x0002))
35933594
#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (UINT16_C(0x0001))
3594-
#define __WASI_UNLINK_REMOVEDIR (UINT8_C(0x01))
35953595
#define __WASI_WHENCE_CUR (UINT8_C(0))
35963596
#define __WASI_WHENCE_END (UINT8_C(1))
35973597
#define __WASI_WHENCE_SET (UINT8_C(2))

expected/wasm32-wasi/undefined-symbols.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ __wasi_file_rename
5050
__wasi_file_stat_get
5151
__wasi_file_stat_set_times
5252
__wasi_file_symlink
53-
__wasi_file_unlink
53+
__wasi_file_unlink_directory
54+
__wasi_file_unlink_file
5455
__wasi_poll_oneoff
5556
__wasi_proc_exit
5657
__wasi_random_get

libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <unistd.h>
1212

1313
int unlinkat(int fd, const char *path, int flag) {
14+
#ifdef __wasilibc_unmodified_upstream // unlink
1415
__wasi_ulflags_t ulflags = 0;
1516
if ((flag & AT_REMOVEDIR) != 0)
1617
ulflags |= __WASI_UNLINK_REMOVEDIR;
@@ -20,5 +21,22 @@ int unlinkat(int fd, const char *path, int flag) {
2021
errno = errno_fixup_directory(fd, error);
2122
return -1;
2223
}
24+
#else
25+
__wasi_errno_t error;
26+
size_t path_len = strlen(path);
27+
if ((flag & AT_REMOVEDIR) != 0) {
28+
error = __wasi_file_unlink_directory(fd, path, path_len);
29+
if (error != 0) {
30+
errno = errno_fixup_directory(fd, error);
31+
return -1;
32+
}
33+
} else {
34+
error = __wasi_file_unlink_file(fd, path, path_len);
35+
if (error != 0) {
36+
errno = error;
37+
return -1;
38+
}
39+
}
40+
#endif
2341
return 0;
2442
}

libc-bottom-half/headers/public/wasi/core.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ typedef uint64_t __wasi_rights_t;
211211
#define __WASI_RIGHT_FILE_FSTAT_SET_SIZE (UINT64_C(0x0000000000400000))
212212
#define __WASI_RIGHT_FILE_FSTAT_SET_TIMES (UINT64_C(0x0000000000800000))
213213
#define __WASI_RIGHT_FILE_SYMLINK (UINT64_C(0x0000000001000000))
214-
#define __WASI_RIGHT_FILE_UNLINK (UINT64_C(0x0000000002000000))
215-
#define __WASI_RIGHT_POLL_FD_READWRITE (UINT64_C(0x0000000004000000))
216-
#define __WASI_RIGHT_SOCK_SHUTDOWN (UINT64_C(0x0000000008000000))
214+
#define __WASI_RIGHT_FILE_UNLINK_FILE (UINT64_C(0x0000000002000000))
215+
#define __WASI_RIGHT_FILE_UNLINK_DIRECTORY (UINT64_C(0x0000000004000000))
216+
#define __WASI_RIGHT_POLL_FD_READWRITE (UINT64_C(0x0000000008000000))
217+
#define __WASI_RIGHT_SOCK_SHUTDOWN (UINT64_C(0x0000000010000000))
217218

218219
typedef uint16_t __wasi_roflags_t;
219220
#define __WASI_SOCK_RECV_DATA_TRUNCATED (UINT16_C(0x0001))
@@ -262,9 +263,6 @@ typedef uint16_t __wasi_subclockflags_t;
262263

263264
typedef uint64_t __wasi_timestamp_t;
264265

265-
typedef uint8_t __wasi_ulflags_t;
266-
#define __WASI_UNLINK_REMOVEDIR (UINT8_C(0x01))
267-
268266
typedef uint64_t __wasi_userdata_t;
269267

270268
typedef uint8_t __wasi_whence_t;
@@ -624,12 +622,17 @@ __wasi_errno_t __wasi_file_symlink(
624622
size_t new_path_len
625623
) __WASI_SYSCALL_NAME(file_symlink) __attribute__((__warn_unused_result__));
626624

627-
__wasi_errno_t __wasi_file_unlink(
625+
__wasi_errno_t __wasi_file_unlink_file(
628626
__wasi_fd_t fd,
629627
const char *path,
630-
size_t path_len,
631-
__wasi_ulflags_t flags
632-
) __WASI_SYSCALL_NAME(file_unlink) __attribute__((__warn_unused_result__));
628+
size_t path_len
629+
) __WASI_SYSCALL_NAME(file_unlink_file) __attribute__((__warn_unused_result__));
630+
631+
__wasi_errno_t __wasi_file_unlink_directory(
632+
__wasi_fd_t fd,
633+
const char *path,
634+
size_t path_len
635+
) __WASI_SYSCALL_NAME(file_unlink_directory) __attribute__((__warn_unused_result__));
633636

634637
__wasi_errno_t __wasi_poll_oneoff(
635638
const __wasi_subscription_t *in,

0 commit comments

Comments
 (0)