@@ -31,7 +31,7 @@ int wasmfs_create_directory(const char* path, int mode, backend_t backend);
31
31
// Return a pointer to the JS buffer in HEAPU8.
32
32
// The buffer will also contain the file length.
33
33
// 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) {
35
35
static_assert (sizeof (off_t ) == 8 , " File offset type must be 64-bit" );
36
36
37
37
struct stat file;
@@ -73,7 +73,7 @@ void* _wasmfs_read_file(char* path) {
73
73
74
74
// Writes to a file, possibly creating it, and returns the number of bytes
75
75
// 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) {
77
77
auto parsedParent = path::parseParent (pathname);
78
78
if (parsedParent.getError ()) {
79
79
return 0 ;
@@ -123,37 +123,37 @@ int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
123
123
return data_size;
124
124
}
125
125
126
- int _wasmfs_mkdir (char * path, mode_t mode) {
126
+ int _wasmfs_mkdir (const char * path, mode_t mode) {
127
127
return __syscall_mkdirat (AT_FDCWD, path, mode);
128
128
}
129
129
130
- int _wasmfs_rmdir (char * path) {
130
+ int _wasmfs_rmdir (const char * path) {
131
131
return __syscall_unlinkat (AT_FDCWD, path, AT_REMOVEDIR);
132
132
}
133
133
134
- int _wasmfs_open (char * path, int flags, mode_t mode) {
134
+ int _wasmfs_open (const char * path, int flags, mode_t mode) {
135
135
return __syscall_openat (AT_FDCWD, path, flags, mode);
136
136
}
137
137
138
138
int _wasmfs_allocate (int fd, off_t offset, off_t len) {
139
139
return __syscall_fallocate (fd, 0 , offset, len);
140
140
}
141
141
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) {
143
143
return __syscall_mknodat (AT_FDCWD, path, mode, dev);
144
144
}
145
145
146
- int _wasmfs_unlink (char * path) {
146
+ int _wasmfs_unlink (const char * path) {
147
147
return __syscall_unlinkat (AT_FDCWD, path, 0 );
148
148
}
149
149
150
- int _wasmfs_chdir (char * path) { return __syscall_chdir (path); }
150
+ int _wasmfs_chdir (const char * path) { return __syscall_chdir (path); }
151
151
152
- int _wasmfs_symlink (char * old_path, char * new_path) {
152
+ int _wasmfs_symlink (const char * old_path, const char * new_path) {
153
153
return __syscall_symlinkat (old_path, AT_FDCWD, new_path);
154
154
}
155
155
156
- intptr_t _wasmfs_readlink (char * path) {
156
+ intptr_t _wasmfs_readlink (const char * path) {
157
157
static thread_local void * readBuf = nullptr ;
158
158
readBuf = realloc (readBuf, PATH_MAX);
159
159
int bytes =
@@ -191,13 +191,13 @@ int _wasmfs_pwrite(int fd, void* buf, size_t count, off_t offset) {
191
191
return numBytes;
192
192
}
193
193
194
- int _wasmfs_chmod (char * path, mode_t mode) {
194
+ int _wasmfs_chmod (const char * path, mode_t mode) {
195
195
return __syscall_chmod (path, mode);
196
196
}
197
197
198
198
int _wasmfs_fchmod (int fd, mode_t mode) { return __syscall_fchmod (fd, mode); }
199
199
200
- int _wasmfs_lchmod (char * path, mode_t mode) {
200
+ int _wasmfs_lchmod (const char * path, mode_t mode) {
201
201
return __syscall_fchmodat2 (AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW);
202
202
}
203
203
@@ -210,7 +210,7 @@ int _wasmfs_llseek(int fd, off_t offset, int whence) {
210
210
return newOffset;
211
211
}
212
212
213
- int _wasmfs_rename (char * oldpath, char * newpath) {
213
+ int _wasmfs_rename (const char * oldpath, const char * newpath) {
214
214
return __syscall_renameat (AT_FDCWD, oldpath, AT_FDCWD, newpath);
215
215
}
216
216
@@ -240,7 +240,7 @@ int _wasmfs_pread(int fd, void* buf, size_t count, off_t offset) {
240
240
return numBytes;
241
241
}
242
242
243
- int _wasmfs_truncate (char * path, off_t length) {
243
+ int _wasmfs_truncate (const char * path, off_t length) {
244
244
return __syscall_truncate64 (path, length);
245
245
}
246
246
@@ -262,7 +262,7 @@ int _wasmfs_munmap(void* addr, size_t length) {
262
262
return __syscall_munmap (addr, length);
263
263
}
264
264
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) {
266
266
struct timespec times[2 ];
267
267
times[0 ].tv_sec = atime_ms / 1000 ;
268
268
times[0 ].tv_nsec = (atime_ms % 1000 ) * 1000000 ;
@@ -272,18 +272,18 @@ int _wasmfs_utime(char* path, long atime_ms, long mtime_ms) {
272
272
return __syscall_utimensat (AT_FDCWD, path, times, 0 );
273
273
}
274
274
275
- int _wasmfs_stat (char * path, struct stat * statBuf) {
275
+ int _wasmfs_stat (const char * path, struct stat * statBuf) {
276
276
return __syscall_stat64 (path, statBuf);
277
277
}
278
278
279
- int _wasmfs_lstat (char * path, struct stat * statBuf) {
279
+ int _wasmfs_lstat (const char * path, struct stat * statBuf) {
280
280
return __syscall_lstat64 (path, statBuf);
281
281
}
282
282
283
283
// The legacy JS API requires a mountpoint to already exist, so WasmFS will
284
284
// attempt to remove the target directory if it exists before replacing it with
285
285
// 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) {
287
287
int err = __syscall_rmdir (path);
288
288
289
289
// 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) {
299
299
// ENOENT - if nothing exists there
300
300
// EISDIR - if it is a directory
301
301
// EEXIST - if it is a normal file
302
- int _wasmfs_identify (char * path) {
302
+ int _wasmfs_identify (const char * path) {
303
303
struct stat file;
304
304
int err = 0 ;
305
305
err = stat (path, &file);
@@ -318,7 +318,7 @@ struct wasmfs_readdir_state {
318
318
struct dirent ** entries;
319
319
};
320
320
321
- struct wasmfs_readdir_state * _wasmfs_readdir_start (char * path) {
321
+ struct wasmfs_readdir_state * _wasmfs_readdir_start (const char * path) {
322
322
struct dirent ** entries;
323
323
int nentries = scandir (path, &entries, NULL , alphasort);
324
324
if (nentries == -1 ) {
0 commit comments