Skip to content

Commit 24a54bf

Browse files
committed
WasmFS JS API: prefer const char*
1 parent a98e0f3 commit 24a54bf

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

system/lib/wasmfs/js_api.cpp

Lines changed: 19 additions & 19 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, const char* data, size_t data_size) {
7373
auto parsedParent = path::parseParent(pathname);
7474
if (parsedParent.getError()) {
7575
return 0;
@@ -119,35 +119,35 @@ 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
return __syscall_openat(AT_FDCWD, path, flags, mode);
130130
}
131131

132132
int _wasmfs_allocate(int fd, off_t offset, off_t len) {
133133
return __syscall_fallocate(fd, 0, offset, len);
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
return __syscall_mknodat(AT_FDCWD, path, mode, dev);
138138
}
139139

140-
int _wasmfs_unlink(char* path) {
140+
int _wasmfs_unlink(const char* path) {
141141
return __syscall_unlinkat(AT_FDCWD, path, 0);
142142
}
143143

144-
int _wasmfs_chdir(char* path) { return __syscall_chdir(path); }
144+
int _wasmfs_chdir(const char* path) { return __syscall_chdir(path); }
145145

146-
int _wasmfs_symlink(char* old_path, char* new_path) {
146+
int _wasmfs_symlink(const char* old_path, const char* new_path) {
147147
return __syscall_symlink(old_path, new_path);
148148
}
149149

150-
intptr_t _wasmfs_readlink(char* path) {
150+
intptr_t _wasmfs_readlink(const char* path) {
151151
static thread_local void* readBuf = nullptr;
152152
readBuf = realloc(readBuf, PATH_MAX);
153153
int err = __syscall_readlinkat(AT_FDCWD, path, (char*)readBuf, PATH_MAX);
@@ -183,15 +183,15 @@ int _wasmfs_pwrite(int fd, void *buf, size_t count, off_t offset) {
183183
return numBytes;
184184
}
185185

186-
int _wasmfs_chmod(char* path, mode_t mode) {
186+
int _wasmfs_chmod(const char* path, mode_t mode) {
187187
return __syscall_chmod(path, mode);
188188
}
189189

190190
int _wasmfs_fchmod(int fd, mode_t mode) {
191191
return __syscall_fchmod(fd, mode);
192192
}
193193

194-
int _wasmfs_lchmod(char* path, mode_t mode) {
194+
int _wasmfs_lchmod(const char* path, mode_t mode) {
195195
return __syscall_fchmodat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW);
196196
}
197197

@@ -204,7 +204,7 @@ int _wasmfs_llseek(int fd, off_t offset, int whence) {
204204
return newOffset;
205205
}
206206

207-
int _wasmfs_rename(char* oldpath, char* newpath) {
207+
int _wasmfs_rename(const char* oldpath, const char* newpath) {
208208
return __syscall_renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
209209
};
210210

@@ -234,7 +234,7 @@ int _wasmfs_pread(int fd, void *buf, size_t count, off_t offset) {
234234
return numBytes;
235235
}
236236

237-
int _wasmfs_truncate(char* path, off_t length) {
237+
int _wasmfs_truncate(const char* path, off_t length) {
238238
return __syscall_truncate64(path, length);
239239
}
240240

@@ -246,19 +246,19 @@ int _wasmfs_close(int fd) {
246246
return __wasi_fd_close(fd);
247247
}
248248

249-
int _wasmfs_stat(char* path, struct stat* statBuf) {
249+
int _wasmfs_stat(const char* path, struct stat* statBuf) {
250250
return __syscall_stat64(path, statBuf);
251251
}
252252

253-
int _wasmfs_lstat(char* path, struct stat* statBuf) {
253+
int _wasmfs_lstat(const char* path, struct stat* statBuf) {
254254
return __syscall_lstat64(path, statBuf);
255255
}
256256

257257
// Helper method that identifies what a path is:
258258
// ENOENT - if nothing exists there
259259
// EISDIR - if it is a directory
260260
// EEXIST - if it is a normal file
261-
int _wasmfs_identify(char* path) {
261+
int _wasmfs_identify(const char* path) {
262262
struct stat file;
263263
int err = 0;
264264
err = stat(path, &file);
@@ -277,7 +277,7 @@ struct wasmfs_readdir_state {
277277
struct dirent** entries;
278278
};
279279

280-
struct wasmfs_readdir_state* _wasmfs_readdir_start(char* path) {
280+
struct wasmfs_readdir_state* _wasmfs_readdir_start(const char* path) {
281281
struct dirent** entries;
282282
int nentries = scandir(path, &entries, NULL, alphasort);
283283
if (nentries == -1) {

0 commit comments

Comments
 (0)