@@ -24,15 +24,15 @@ extern "C" {
24
24
25
25
// TODO: Replace forward declarations with #include <emscripten/wasmfs.h> and
26
26
// 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);
30
30
31
31
// Copy the file specified by the pathname into JS.
32
32
// Return a pointer to the JS buffer in HEAPU8.
33
33
// The buffer will also contain the file length.
34
34
// 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) {
36
36
static_assert (sizeof (off_t ) == 8 , " File offset type must be 64-bit" );
37
37
38
38
struct stat file;
@@ -74,7 +74,7 @@ void* _wasmfs_read_file(char* path) {
74
74
75
75
// Writes to a file, possibly creating it, and returns the number of bytes
76
76
// 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) {
78
78
auto parsedParent = path::parseParent (pathname);
79
79
if (parsedParent.getError ()) {
80
80
return 0 ;
@@ -124,37 +124,37 @@ int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
124
124
return data_size;
125
125
}
126
126
127
- int _wasmfs_mkdir (char * path, mode_t mode) {
127
+ int _wasmfs_mkdir (const char * path, mode_t mode) {
128
128
return __syscall_mkdirat (AT_FDCWD, path, mode);
129
129
}
130
130
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);
133
133
}
134
134
135
- int _wasmfs_open (char * path, int flags, mode_t mode) {
135
+ int _wasmfs_open (const char * path, int flags, mode_t mode) {
136
136
return __syscall_openat (AT_FDCWD, path, flags, mode);
137
137
}
138
138
139
139
int _wasmfs_allocate (int fd, off_t offset, off_t len) {
140
140
return __syscall_fallocate (fd, 0 , offset, len);
141
141
}
142
142
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) {
144
144
return __syscall_mknodat (AT_FDCWD, path, mode, dev);
145
145
}
146
146
147
- int _wasmfs_unlink (char * path) {
147
+ int _wasmfs_unlink (const char * path) {
148
148
return __syscall_unlinkat (AT_FDCWD, path, 0 );
149
149
}
150
150
151
- int _wasmfs_chdir (char * path) { return __syscall_chdir (path); }
151
+ int _wasmfs_chdir (const char * path) { return __syscall_chdir (path); }
152
152
153
- int _wasmfs_symlink (char * old_path, char * new_path) {
153
+ int _wasmfs_symlink (const char * old_path, const char * new_path) {
154
154
return __syscall_symlink (old_path, new_path);
155
155
}
156
156
157
- intptr_t _wasmfs_readlink (char * path) {
157
+ intptr_t _wasmfs_readlink (const char * path) {
158
158
static thread_local void * readBuf = nullptr ;
159
159
readBuf = realloc (readBuf, PATH_MAX);
160
160
int bytes =
@@ -192,13 +192,13 @@ int _wasmfs_pwrite(int fd, void* buf, size_t count, off_t offset) {
192
192
return numBytes;
193
193
}
194
194
195
- int _wasmfs_chmod (char * path, mode_t mode) {
195
+ int _wasmfs_chmod (const char * path, mode_t mode) {
196
196
return __syscall_chmod (path, mode);
197
197
}
198
198
199
199
int _wasmfs_fchmod (int fd, mode_t mode) { return __syscall_fchmod (fd, mode); }
200
200
201
- int _wasmfs_lchmod (char * path, mode_t mode) {
201
+ int _wasmfs_lchmod (const char * path, mode_t mode) {
202
202
return __syscall_fchmodat2 (AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW);
203
203
}
204
204
@@ -211,7 +211,7 @@ int _wasmfs_llseek(int fd, off_t offset, int whence) {
211
211
return newOffset;
212
212
}
213
213
214
- int _wasmfs_rename (char * oldpath, char * newpath) {
214
+ int _wasmfs_rename (const char * oldpath, const char * newpath) {
215
215
return __syscall_renameat (AT_FDCWD, oldpath, AT_FDCWD, newpath);
216
216
}
217
217
@@ -241,7 +241,7 @@ int _wasmfs_pread(int fd, void* buf, size_t count, off_t offset) {
241
241
return numBytes;
242
242
}
243
243
244
- int _wasmfs_truncate (char * path, off_t length) {
244
+ int _wasmfs_truncate (const char * path, off_t length) {
245
245
return __syscall_truncate64 (path, length);
246
246
}
247
247
@@ -263,7 +263,7 @@ int _wasmfs_munmap(void* addr, size_t length) {
263
263
return __syscall_munmap (addr, length);
264
264
}
265
265
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) {
267
267
struct timespec times[2 ];
268
268
times[0 ].tv_sec = atime_ms / 1000 ;
269
269
times[0 ].tv_nsec = (atime_ms % 1000 ) * 1000000 ;
@@ -273,18 +273,18 @@ int _wasmfs_utime(char* path, long atime_ms, long mtime_ms) {
273
273
return __syscall_utimensat (AT_FDCWD, path, times, 0 );
274
274
}
275
275
276
- int _wasmfs_stat (char * path, struct stat * statBuf) {
276
+ int _wasmfs_stat (const char * path, struct stat * statBuf) {
277
277
return __syscall_stat64 (path, statBuf);
278
278
}
279
279
280
- int _wasmfs_lstat (char * path, struct stat * statBuf) {
280
+ int _wasmfs_lstat (const char * path, struct stat * statBuf) {
281
281
return __syscall_lstat64 (path, statBuf);
282
282
}
283
283
284
284
// The legacy JS API requires a mountpoint to already exist, so WasmFS will
285
285
// attempt to remove the target directory if it exists before replacing it with
286
286
// 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) {
288
288
int err = __syscall_rmdir (path);
289
289
290
290
// 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) {
298
298
299
299
// WasmFS will always remove the mounted directory, regardless of if the
300
300
// directory existed before.
301
- int _wasmfs_unmount (char * path) { return wasmfs_unmount (path); }
301
+ int _wasmfs_unmount (const char * path) { return wasmfs_unmount (path); }
302
302
303
303
// Helper method that identifies what a path is:
304
304
// ENOENT - if nothing exists there
305
305
// EISDIR - if it is a directory
306
306
// EEXIST - if it is a normal file
307
- int _wasmfs_identify (char * path) {
307
+ int _wasmfs_identify (const char * path) {
308
308
struct stat file;
309
309
int err = 0 ;
310
310
err = stat (path, &file);
@@ -323,7 +323,7 @@ struct wasmfs_readdir_state {
323
323
struct dirent ** entries;
324
324
};
325
325
326
- struct wasmfs_readdir_state * _wasmfs_readdir_start (char * path) {
326
+ struct wasmfs_readdir_state * _wasmfs_readdir_start (const char * path) {
327
327
struct dirent ** entries;
328
328
int nentries = scandir (path, &entries, NULL , alphasort);
329
329
if (nentries == -1 ) {
0 commit comments