Skip to content

Commit 768961e

Browse files
committed
WasmFS JS API: prefer const char*
1 parent 2e286e4 commit 768961e

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

system/lib/wasmfs/js_api.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int wasmfs_create_directory(const char* path, int mode, backend_t backend);
3131
// Return a pointer to the JS buffer in HEAPU8.
3232
// The buffer will also contain the file length.
3333
// TODO: Use WasmFS ErrnoError handling instead of aborting on failure.
34-
void* _wasmfs_read_file(char* path) {
34+
void* _wasmfs_read_file(const char* path) {
3535
static_assert(sizeof(off_t) == 8, "File offset type must be 64-bit");
3636

3737
struct stat file;
@@ -73,7 +73,7 @@ void* _wasmfs_read_file(char* path) {
7373

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

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

130-
int _wasmfs_rmdir(char* path) {
130+
int _wasmfs_rmdir(const char* path) {
131131
return __syscall_unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
132132
}
133133

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

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

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

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

150-
int _wasmfs_chdir(char* path) { return __syscall_chdir(path); }
150+
int _wasmfs_chdir(const char* path) { return __syscall_chdir(path); }
151151

152-
int _wasmfs_symlink(char* old_path, char* new_path) {
152+
int _wasmfs_symlink(const char* old_path, const char* new_path) {
153153
return __syscall_symlinkat(old_path, AT_FDCWD, new_path);
154154
}
155155

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

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

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

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

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

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

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

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

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

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

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

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

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

289289
// The legacy JS API mount requires the directory to already exist, but we
@@ -299,7 +299,7 @@ int _wasmfs_mount(char* path, wasmfs::backend_t created_backend) {
299299
// ENOENT - if nothing exists there
300300
// EISDIR - if it is a directory
301301
// EEXIST - if it is a normal file
302-
int _wasmfs_identify(char* path) {
302+
int _wasmfs_identify(const char* path) {
303303
struct stat file;
304304
int err = 0;
305305
err = stat(path, &file);
@@ -318,7 +318,7 @@ struct wasmfs_readdir_state {
318318
struct dirent** entries;
319319
};
320320

321-
struct wasmfs_readdir_state* _wasmfs_readdir_start(char* path) {
321+
struct wasmfs_readdir_state* _wasmfs_readdir_start(const char* path) {
322322
struct dirent** entries;
323323
int nentries = scandir(path, &entries, NULL, alphasort);
324324
if (nentries == -1) {

0 commit comments

Comments
 (0)