Skip to content

Commit 8af2200

Browse files
authored
[WasmFS] Use const char* in JS API impl. NFC (#23825)
1 parent 58f34ff commit 8af2200

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

system/lib/wasmfs/js_api.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
// Return a pointer to the JS buffer in HEAPU8.
2828
// The buffer will also contain the file length.
2929
// TODO: Use WasmFS ErrnoError handling instead of aborting on failure.
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,37 +119,37 @@ int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
119119
return data_size;
120120
}
121121

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

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

130-
int _wasmfs_open(char* path, int flags, mode_t mode) {
130+
int _wasmfs_open(const char* path, int flags, mode_t mode) {
131131
return __syscall_openat(AT_FDCWD, (intptr_t)path, flags, mode);
132132
}
133133

134134
int _wasmfs_allocate(int fd, off_t offset, off_t len) {
135135
return __syscall_fallocate(fd, 0, offset, len);
136136
}
137137

138-
int _wasmfs_mknod(char* path, mode_t mode, dev_t dev) {
138+
int _wasmfs_mknod(const char* path, mode_t mode, dev_t dev) {
139139
return __syscall_mknodat(AT_FDCWD, (intptr_t)path, mode, dev);
140140
}
141141

142-
int _wasmfs_unlink(char* path) {
142+
int _wasmfs_unlink(const char* path) {
143143
return __syscall_unlinkat(AT_FDCWD, (intptr_t)path, 0);
144144
}
145145

146-
int _wasmfs_chdir(char* path) { return __syscall_chdir((intptr_t)path); }
146+
int _wasmfs_chdir(const char* path) { return __syscall_chdir((intptr_t)path); }
147147

148-
int _wasmfs_symlink(char* old_path, char* new_path) {
148+
int _wasmfs_symlink(const char* old_path, const char* new_path) {
149149
return __syscall_symlinkat((intptr_t)old_path, AT_FDCWD, (intptr_t)new_path);
150150
}
151151

152-
intptr_t _wasmfs_readlink(char* path) {
152+
intptr_t _wasmfs_readlink(const char* path) {
153153
static thread_local char* readBuf = (char*)malloc(PATH_MAX);
154154
int bytes =
155155
__syscall_readlinkat(AT_FDCWD, (intptr_t)path, (intptr_t)readBuf, PATH_MAX);
@@ -186,13 +186,13 @@ int _wasmfs_pwrite(int fd, void* buf, size_t count, off_t offset) {
186186
return numBytes;
187187
}
188188

189-
int _wasmfs_chmod(char* path, mode_t mode) {
189+
int _wasmfs_chmod(const char* path, mode_t mode) {
190190
return __syscall_chmod((intptr_t)path, mode);
191191
}
192192

193193
int _wasmfs_fchmod(int fd, mode_t mode) { return __syscall_fchmod(fd, mode); }
194194

195-
int _wasmfs_lchmod(char* path, mode_t mode) {
195+
int _wasmfs_lchmod(const char* path, mode_t mode) {
196196
return __syscall_fchmodat2(
197197
AT_FDCWD, (intptr_t)path, mode, AT_SYMLINK_NOFOLLOW);
198198
}
@@ -206,7 +206,7 @@ int _wasmfs_llseek(int fd, off_t offset, int whence) {
206206
return newOffset;
207207
}
208208

209-
int _wasmfs_rename(char* oldpath, char* newpath) {
209+
int _wasmfs_rename(const char* oldpath, const char* newpath) {
210210
return __syscall_renameat(
211211
AT_FDCWD, (intptr_t)oldpath, AT_FDCWD, (intptr_t)newpath);
212212
}
@@ -237,7 +237,7 @@ int _wasmfs_pread(int fd, void* buf, size_t count, off_t offset) {
237237
return numBytes;
238238
}
239239

240-
int _wasmfs_truncate(char* path, off_t length) {
240+
int _wasmfs_truncate(const char* path, off_t length) {
241241
return __syscall_truncate64((intptr_t)path, length);
242242
}
243243

@@ -259,7 +259,7 @@ int _wasmfs_munmap(void* addr, size_t length) {
259259
return __syscall_munmap((intptr_t)addr, length);
260260
}
261261

262-
int _wasmfs_utime(char* path, long atime_ms, long mtime_ms) {
262+
int _wasmfs_utime(const char* path, long atime_ms, long mtime_ms) {
263263
struct timespec times[2];
264264
times[0].tv_sec = atime_ms / 1000;
265265
times[0].tv_nsec = (atime_ms % 1000) * 1000000;
@@ -269,18 +269,18 @@ int _wasmfs_utime(char* path, long atime_ms, long mtime_ms) {
269269
return __syscall_utimensat(AT_FDCWD, (intptr_t)path, (intptr_t)times, 0);
270270
}
271271

272-
int _wasmfs_stat(char* path, struct stat* statBuf) {
272+
int _wasmfs_stat(const char* path, struct stat* statBuf) {
273273
return __syscall_stat64((intptr_t)path, (intptr_t)statBuf);
274274
}
275275

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

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

286286
// The legacy JS API mount requires the directory to already exist, but we
@@ -296,7 +296,7 @@ int _wasmfs_mount(char* path, ::backend_t created_backend) {
296296
// ENOENT - if nothing exists there
297297
// EISDIR - if it is a directory
298298
// EEXIST - if it is a normal file
299-
int _wasmfs_identify(char* path) {
299+
int _wasmfs_identify(const char* path) {
300300
struct stat file;
301301
int err = 0;
302302
err = stat(path, &file);
@@ -315,7 +315,7 @@ struct wasmfs_readdir_state {
315315
struct dirent** entries;
316316
};
317317

318-
struct wasmfs_readdir_state* _wasmfs_readdir_start(char* path) {
318+
struct wasmfs_readdir_state* _wasmfs_readdir_start(const char* path) {
319319
struct dirent** entries;
320320
int nentries = scandir(path, &entries, NULL, alphasort);
321321
if (nentries == -1) {

0 commit comments

Comments
 (0)