Skip to content

Commit 1d01e06

Browse files
committed
WasmFS JS API: prefer const char*
1 parent cba3981 commit 1d01e06

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

system/lib/wasmfs/js_api.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ using namespace wasmfs;
2222

2323
extern "C" {
2424

25-
__wasi_fd_t wasmfs_create_file(char* pathname, mode_t mode, backend_t backend);
25+
__wasi_fd_t wasmfs_create_file(const char* pathname, mode_t mode, backend_t backend);
2626

2727
// Copy the file specified by the pathname into JS.
2828
// Return a pointer to the JS buffer in HEAPU8.
2929
// The buffer will also contain the file length.
30-
void* _wasmfs_read_file(char* path) {
30+
void* _wasmfs_read_file(const char* path) {
3131
static_assert(sizeof(off_t) == 8, "File offset type must be 64-bit");
3232

3333
struct stat file;
@@ -69,7 +69,7 @@ void* _wasmfs_read_file(char* path) {
6969

7070
// Writes to a file, possibly creating it, and returns the number of bytes
7171
// written successfully. If the file already exists, appends to it.
72-
int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
72+
int _wasmfs_write_file(const char* pathname, char* data, size_t data_size) {
7373
auto parsedParent = path::parseParent(pathname);
7474
if (parsedParent.getError()) {
7575
return 0;
@@ -119,33 +119,33 @@ int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
119119
return data_size;
120120
}
121121

122-
int _wasmfs_mkdir(char* path, mode_t mode) {
122+
int _wasmfs_mkdir(const char* path, mode_t mode) {
123123
return __syscall_mkdirat(AT_FDCWD, path, mode);
124124
}
125125

126-
int _wasmfs_rmdir(char* path){ return __syscall_unlinkat(AT_FDCWD, path, AT_REMOVEDIR); }
126+
int _wasmfs_rmdir(const char* path){ return __syscall_unlinkat(AT_FDCWD, path, AT_REMOVEDIR); }
127127

128-
int _wasmfs_open(char* path, int flags, mode_t mode) {
128+
int _wasmfs_open(const char* path, int flags, mode_t mode) {
129129
int err = __syscall_openat(AT_FDCWD, path, flags, mode);
130130
if (err == -1) {
131131
return -errno;
132132
}
133133
return err;
134134
}
135135

136-
int _wasmfs_mknod(char* path, mode_t mode, dev_t dev) {
136+
int _wasmfs_mknod(const char* path, mode_t mode, dev_t dev) {
137137
int err = __syscall_mknodat(AT_FDCWD, path, mode, dev);
138138
if (err == -1) {
139139
return errno;
140140
}
141141
return err;
142142
}
143143

144-
int _wasmfs_unlink(char* path) {
144+
int _wasmfs_unlink(const char* path) {
145145
return __syscall_unlinkat(AT_FDCWD, path, 0);
146146
}
147147

148-
int _wasmfs_chdir(char* path) { return __syscall_chdir(path); }
148+
int _wasmfs_chdir(const char* path) { return __syscall_chdir(path); }
149149

150150
int _wasmfs_symlink(char* old_path, char* new_path) {
151151
return __syscall_symlink(old_path, new_path);
@@ -177,19 +177,19 @@ int _wasmfs_pwrite(int fd, void *buf, size_t count, off_t offset) {
177177
return numBytes;
178178
}
179179

180-
int _wasmfs_chmod(char* path, mode_t mode) {
180+
int _wasmfs_chmod(const char* path, mode_t mode) {
181181
return __syscall_chmod(path, mode);
182182
}
183183

184184
int _wasmfs_fchmod(int fd, mode_t mode) {
185185
return __syscall_fchmod(fd, mode);
186186
}
187187

188-
int _wasmfs_lchmod(char* path, mode_t mode) {
188+
int _wasmfs_lchmod(const char* path, mode_t mode) {
189189
return __syscall_fchmodat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW);
190190
}
191191

192-
int _wasmfs_rename(char* oldpath, char* newpath) {
192+
int _wasmfs_rename(const char* oldpath, const char* newpath) {
193193
int err = __syscall_renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
194194
if (err == -1) {
195195
return errno;
@@ -227,15 +227,15 @@ int _wasmfs_close(int fd) {
227227
return __wasi_fd_close(fd);
228228
}
229229

230-
int _wasmfs_stat(char* path, struct stat* statBuf) {
230+
int _wasmfs_stat(const char* path, struct stat* statBuf) {
231231
int err = __syscall_stat64(path, statBuf);
232232
if (err == -1) {
233233
return errno;
234234
}
235235
return err;
236236
}
237237

238-
int _wasmfs_lstat(char* path, struct stat* statBuf) {
238+
int _wasmfs_lstat(const char* path, struct stat* statBuf) {
239239
int err = __syscall_lstat64(path, statBuf);
240240
if (err == -1) {
241241
return errno;
@@ -247,7 +247,7 @@ int _wasmfs_lstat(char* path, struct stat* statBuf) {
247247
// ENOENT - if nothing exists there
248248
// EISDIR - if it is a directory
249249
// EEXIST - if it is a normal file
250-
int _wasmfs_identify(char* path) {
250+
int _wasmfs_identify(const char* path) {
251251
struct stat file;
252252
int err = 0;
253253
err = stat(path, &file);
@@ -266,7 +266,7 @@ struct wasmfs_readdir_state {
266266
struct dirent** entries;
267267
};
268268

269-
struct wasmfs_readdir_state* _wasmfs_readdir_start(char* path) {
269+
struct wasmfs_readdir_state* _wasmfs_readdir_start(const char* path) {
270270
struct dirent** entries;
271271
int nentries = scandir(path, &entries, NULL, alphasort);
272272
if (nentries == -1) {

0 commit comments

Comments
 (0)