Skip to content

Commit f7a239f

Browse files
committed
WasmFS JS API: prefer const char*
1 parent 6d63e8b commit f7a239f

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

system/include/emscripten/wasmfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int wasmfs_create_directory(const char* path __attribute__((nonnull)), mode_t mo
3636

3737
// Unmounts the directory (Which must be a valid mountpoint) at a specific path.
3838
// Returns 0 on success, or a negative value on error.
39-
int wasmfs_unmount(char* path);
39+
int wasmfs_unmount(const char* path);
4040

4141
// Backend creation
4242

system/lib/wasmfs/js_api.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ extern "C" {
2424

2525
// TODO: Replace forward declarations with #include <emscripten/wasmfs.h> and
2626
// resolve wasmfs::backend_t namespace conflicts.
27-
__wasi_fd_t wasmfs_create_file(char* pathname, mode_t mode, backend_t backend);
28-
int wasmfs_create_directory(char* path, int mode, backend_t backend);
29-
int wasmfs_unmount(char* path);
27+
__wasi_fd_t wasmfs_create_file(const char* pathname, mode_t mode, backend_t backend);
28+
int wasmfs_create_directory(const char* path, int mode, backend_t backend);
29+
int wasmfs_unmount(const char* path);
3030

3131
// Copy the file specified by the pathname into JS.
3232
// Return a pointer to the JS buffer in HEAPU8.
3333
// The buffer will also contain the file length.
3434
// TODO: Use WasmFS ErrnoError handling instead of aborting on failure.
35-
void* _wasmfs_read_file(char* path) {
35+
void* _wasmfs_read_file(const char* path) {
3636
static_assert(sizeof(off_t) == 8, "File offset type must be 64-bit");
3737

3838
struct stat file;
@@ -74,7 +74,7 @@ void* _wasmfs_read_file(char* path) {
7474

7575
// Writes to a file, possibly creating it, and returns the number of bytes
7676
// written successfully. If the file already exists, appends to it.
77-
int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
77+
int _wasmfs_write_file(const char* pathname, const char* data, size_t data_size) {
7878
auto parsedParent = path::parseParent(pathname);
7979
if (parsedParent.getError()) {
8080
return 0;
@@ -124,37 +124,37 @@ int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
124124
return data_size;
125125
}
126126

127-
int _wasmfs_mkdir(char* path, mode_t mode) {
127+
int _wasmfs_mkdir(const char* path, mode_t mode) {
128128
return __syscall_mkdirat(AT_FDCWD, path, mode);
129129
}
130130

131-
int _wasmfs_rmdir(char* path){
132-
return __syscall_unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
131+
int _wasmfs_rmdir(const char* path){
132+
return __syscall_unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
133133
}
134134

135-
int _wasmfs_open(char* path, int flags, mode_t mode) {
135+
int _wasmfs_open(const char* path, int flags, mode_t mode) {
136136
return __syscall_openat(AT_FDCWD, path, flags, mode);
137137
}
138138

139139
int _wasmfs_allocate(int fd, off_t offset, off_t len) {
140140
return __syscall_fallocate(fd, 0, offset, len);
141141
}
142142

143-
int _wasmfs_mknod(char* path, mode_t mode, dev_t dev) {
143+
int _wasmfs_mknod(const char* path, mode_t mode, dev_t dev) {
144144
return __syscall_mknodat(AT_FDCWD, path, mode, dev);
145145
}
146146

147-
int _wasmfs_unlink(char* path) {
147+
int _wasmfs_unlink(const char* path) {
148148
return __syscall_unlinkat(AT_FDCWD, path, 0);
149149
}
150150

151-
int _wasmfs_chdir(char* path) { return __syscall_chdir(path); }
151+
int _wasmfs_chdir(const char* path) { return __syscall_chdir(path); }
152152

153-
int _wasmfs_symlink(char* old_path, char* new_path) {
153+
int _wasmfs_symlink(const char* old_path, const char* new_path) {
154154
return __syscall_symlink(old_path, new_path);
155155
}
156156

157-
intptr_t _wasmfs_readlink(char* path) {
157+
intptr_t _wasmfs_readlink(const char* path) {
158158
static thread_local void* readBuf = nullptr;
159159
readBuf = realloc(readBuf, PATH_MAX);
160160
int bytes =
@@ -192,13 +192,13 @@ int _wasmfs_pwrite(int fd, void* buf, size_t count, off_t offset) {
192192
return numBytes;
193193
}
194194

195-
int _wasmfs_chmod(char* path, mode_t mode) {
195+
int _wasmfs_chmod(const char* path, mode_t mode) {
196196
return __syscall_chmod(path, mode);
197197
}
198198

199199
int _wasmfs_fchmod(int fd, mode_t mode) { return __syscall_fchmod(fd, mode); }
200200

201-
int _wasmfs_lchmod(char* path, mode_t mode) {
201+
int _wasmfs_lchmod(const char* path, mode_t mode) {
202202
return __syscall_fchmodat2(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW);
203203
}
204204

@@ -211,7 +211,7 @@ int _wasmfs_llseek(int fd, off_t offset, int whence) {
211211
return newOffset;
212212
}
213213

214-
int _wasmfs_rename(char* oldpath, char* newpath) {
214+
int _wasmfs_rename(const char* oldpath, const char* newpath) {
215215
return __syscall_renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
216216
}
217217

@@ -241,7 +241,7 @@ int _wasmfs_pread(int fd, void* buf, size_t count, off_t offset) {
241241
return numBytes;
242242
}
243243

244-
int _wasmfs_truncate(char* path, off_t length) {
244+
int _wasmfs_truncate(const char* path, off_t length) {
245245
return __syscall_truncate64(path, length);
246246
}
247247

@@ -263,7 +263,7 @@ int _wasmfs_munmap(void* addr, size_t length) {
263263
return __syscall_munmap(addr, length);
264264
}
265265

266-
int _wasmfs_utime(char* path, long atime_ms, long mtime_ms) {
266+
int _wasmfs_utime(const char* path, long atime_ms, long mtime_ms) {
267267
struct timespec times[2];
268268
times[0].tv_sec = atime_ms / 1000;
269269
times[0].tv_nsec = (atime_ms % 1000) * 1000000;
@@ -273,18 +273,18 @@ int _wasmfs_utime(char* path, long atime_ms, long mtime_ms) {
273273
return __syscall_utimensat(AT_FDCWD, path, times, 0);
274274
}
275275

276-
int _wasmfs_stat(char* path, struct stat* statBuf) {
276+
int _wasmfs_stat(const char* path, struct stat* statBuf) {
277277
return __syscall_stat64(path, statBuf);
278278
}
279279

280-
int _wasmfs_lstat(char* path, struct stat* statBuf) {
280+
int _wasmfs_lstat(const char* path, struct stat* statBuf) {
281281
return __syscall_lstat64(path, statBuf);
282282
}
283283

284284
// The legacy JS API requires a mountpoint to already exist, so WasmFS will
285285
// attempt to remove the target directory if it exists before replacing it with
286286
// a mounted directory.
287-
int _wasmfs_mount(char* path, wasmfs::backend_t created_backend) {
287+
int _wasmfs_mount(const char* path, wasmfs::backend_t created_backend) {
288288
int err = __syscall_rmdir(path);
289289

290290
// The legacy JS API mount requires the directory to already exist, but we
@@ -298,13 +298,13 @@ int _wasmfs_mount(char* path, wasmfs::backend_t created_backend) {
298298

299299
// WasmFS will always remove the mounted directory, regardless of if the
300300
// directory existed before.
301-
int _wasmfs_unmount(char* path) { return wasmfs_unmount(path); }
301+
int _wasmfs_unmount(const char* path) { return wasmfs_unmount(path); }
302302

303303
// Helper method that identifies what a path is:
304304
// ENOENT - if nothing exists there
305305
// EISDIR - if it is a directory
306306
// EEXIST - if it is a normal file
307-
int _wasmfs_identify(char* path) {
307+
int _wasmfs_identify(const char* path) {
308308
struct stat file;
309309
int err = 0;
310310
err = stat(path, &file);
@@ -323,7 +323,7 @@ struct wasmfs_readdir_state {
323323
struct dirent** entries;
324324
};
325325

326-
struct wasmfs_readdir_state* _wasmfs_readdir_start(char* path) {
326+
struct wasmfs_readdir_state* _wasmfs_readdir_start(const char* path) {
327327
struct dirent** entries;
328328
int nentries = scandir(path, &entries, NULL, alphasort);
329329
if (nentries == -1) {

system/lib/wasmfs/syscalls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ int __syscall_rmdir(const char* path) {
877877

878878
// wasmfs_unmount is similar to __syscall_unlinkat, but assumes AT_REMOVEDIR is
879879
// true and will only unlink mountpoints (Empty and nonempty).
880-
int wasmfs_unmount(char* path) {
880+
int wasmfs_unmount(const char* path) {
881881
auto parsed = path::parseParent(path, AT_FDCWD);
882882
if (auto err = parsed.getError()) {
883883
return err;

0 commit comments

Comments
 (0)