-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #122 `AT_REMOVEDIR` on RISC-V/Spike differs between MacOS and Linux: * Spike/MacOS: 0x080 * Spike/Linux: 0x200 This cannot distinguish naively, so define implicit macro.
- Loading branch information
Showing
12 changed files
with
182 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "sys/stat.h" | ||
#include "string.h" // memset, strncmp | ||
#include "../wasi.h" | ||
|
||
extern int __max_preopen_fd; | ||
|
||
int mkdir(const char *fn, mode_t mode) { | ||
size_t fnlen = strlen(fn); | ||
for (int base_fd = 3; base_fd < __max_preopen_fd; ++base_fd) { | ||
Prestat prestat; | ||
fd_prestat_get(base_fd, &prestat); | ||
size_t l = prestat.u.dir.pr_name_len; // Includes '\0' or not, depending on the environment, | ||
char buf[256]; | ||
fd_prestat_dir_name(base_fd, buf, l); | ||
buf[l] = '\0'; | ||
|
||
if ((*fn == '/' && *buf != '/') || | ||
(*fn != '/' && strcmp(buf, ".") != 0)) | ||
continue; | ||
|
||
const char *fn2 = fn; | ||
size_t fnlen2 = fnlen; | ||
|
||
if (strncmp(fn, buf, l) == 0 && fn[l] == '/') { | ||
fn2 = fn + (l + 1); | ||
fnlen2 = fnlen - (l + 1); | ||
} else if (l == 1 && *buf == '/' && *fn == '/') { | ||
fn2 = fn + 1; | ||
fnlen2 = fnlen - 1; | ||
} | ||
|
||
Filestat fs; | ||
uint32_t result = path_create_directory(base_fd, fn2, fnlen2); | ||
if (result == 0) | ||
return 0; | ||
} | ||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "unistd.h" | ||
#include "errno.h" | ||
#include "string.h" | ||
#include "../wasi.h" | ||
|
||
extern int __max_preopen_fd; | ||
|
||
int rmdir(const char *fn) { | ||
// Search from preopens | ||
size_t fnlen = strlen(fn); | ||
for (int base_fd = 3; base_fd < __max_preopen_fd; ++base_fd) { | ||
Prestat prestat; | ||
if (fd_prestat_get(base_fd, &prestat) != 0) | ||
break; | ||
|
||
size_t l = prestat.u.dir.pr_name_len; // Includes '\0' or not, depending on the environment, | ||
char buf[256]; | ||
fd_prestat_dir_name(base_fd, buf, l); | ||
buf[l] = '\0'; | ||
|
||
if ((*fn == '/' && *buf != '/') || | ||
(*fn != '/' && strcmp(buf, ".") != 0)) | ||
continue; | ||
|
||
const char *fn2 = fn; | ||
size_t fnlen2 = fnlen; | ||
|
||
if (strncmp(fn, buf, l) == 0 && fn[l] == '/') { | ||
fn2 = fn + (l + 1); | ||
fnlen2 = fnlen - (l + 1); | ||
} else if (l == 1 && *buf == '/' && *fn == '/') { | ||
fn2 = fn + 1; | ||
fnlen2 = fnlen - 1; | ||
} | ||
int result = path_remove_directory(base_fd, fn2, fnlen2); | ||
if (result == 0) | ||
return 0; | ||
} | ||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "sys/stat.h" | ||
#include "_syscall.h" | ||
#include "errno.h" | ||
|
||
#if defined(__NR_mkdir) | ||
int mkdir(const char *pathname, mode_t mode) { | ||
int ret; | ||
SYSCALL_RET(__NR_mkdir, ret); | ||
if (ret < 0) { | ||
errno = -ret; | ||
ret = -1; | ||
} | ||
return ret; | ||
} | ||
|
||
#elif defined(__NR_mkdirat) | ||
#include "fcntl.h" | ||
|
||
int mkdir(const char *pathname, mode_t mode) { | ||
return mkdirat(AT_FDCWD, pathname, mode); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "sys/stat.h" | ||
#include "_syscall.h" | ||
#include "errno.h" | ||
|
||
#if defined(__NR_mkdirat) | ||
int mkdirat(int dirfd, const char *pathname, mode_t mode) { | ||
int ret; | ||
SYSCALL_RET(__NR_mkdirat, ret); | ||
if (ret < 0) { | ||
errno = -ret; | ||
ret = -1; | ||
} | ||
return ret; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "sys/stat.h" | ||
#include "_syscall.h" | ||
#include "errno.h" | ||
|
||
#if defined(__NR_rmdir) | ||
int rmdir(const char *pathname) { | ||
int ret; | ||
SYSCALL_RET(__NR_rmdir, ret); | ||
if (ret < 0) { | ||
errno = -ret; | ||
ret = -1; | ||
} | ||
return ret; | ||
} | ||
|
||
#elif defined(__NR_unlinkat) | ||
#include "unistd.h" | ||
#include "fcntl.h" | ||
|
||
int rmdir(const char *pathname) { | ||
return unlinkat(AT_FDCWD, pathname, AT_REMOVEDIR); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters