@@ -27,7 +27,7 @@ extern "C" {
27
27
// Return a pointer to the JS buffer in HEAPU8.
28
28
// The buffer will also contain the file length.
29
29
// 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) {
31
31
static_assert (sizeof (off_t ) == 8 , " File offset type must be 64-bit" );
32
32
33
33
struct stat file;
@@ -69,7 +69,7 @@ void* _wasmfs_read_file(char* path) {
69
69
70
70
// Writes to a file, possibly creating it, and returns the number of bytes
71
71
// 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) {
73
73
auto parsedParent = path::parseParent (pathname);
74
74
if (parsedParent.getError ()) {
75
75
return 0 ;
@@ -119,37 +119,37 @@ int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
119
119
return data_size;
120
120
}
121
121
122
- int _wasmfs_mkdir (char * path, int mode) {
122
+ int _wasmfs_mkdir (const char * path, int mode) {
123
123
return __syscall_mkdirat (AT_FDCWD, (intptr_t )path, mode);
124
124
}
125
125
126
- int _wasmfs_rmdir (char * path) {
126
+ int _wasmfs_rmdir (const char * path) {
127
127
return __syscall_unlinkat (AT_FDCWD, (intptr_t )path, AT_REMOVEDIR);
128
128
}
129
129
130
- int _wasmfs_open (char * path, int flags, mode_t mode) {
130
+ int _wasmfs_open (const char * path, int flags, mode_t mode) {
131
131
return __syscall_openat (AT_FDCWD, (intptr_t )path, flags, mode);
132
132
}
133
133
134
134
int _wasmfs_allocate (int fd, off_t offset, off_t len) {
135
135
return __syscall_fallocate (fd, 0 , offset, len);
136
136
}
137
137
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) {
139
139
return __syscall_mknodat (AT_FDCWD, (intptr_t )path, mode, dev);
140
140
}
141
141
142
- int _wasmfs_unlink (char * path) {
142
+ int _wasmfs_unlink (const char * path) {
143
143
return __syscall_unlinkat (AT_FDCWD, (intptr_t )path, 0 );
144
144
}
145
145
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); }
147
147
148
- int _wasmfs_symlink (char * old_path, char * new_path) {
148
+ int _wasmfs_symlink (const char * old_path, const char * new_path) {
149
149
return __syscall_symlinkat ((intptr_t )old_path, AT_FDCWD, (intptr_t )new_path);
150
150
}
151
151
152
- intptr_t _wasmfs_readlink (char * path) {
152
+ intptr_t _wasmfs_readlink (const char * path) {
153
153
static thread_local char * readBuf = (char *)malloc (PATH_MAX);
154
154
int bytes =
155
155
__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) {
186
186
return numBytes;
187
187
}
188
188
189
- int _wasmfs_chmod (char * path, mode_t mode) {
189
+ int _wasmfs_chmod (const char * path, mode_t mode) {
190
190
return __syscall_chmod ((intptr_t )path, mode);
191
191
}
192
192
193
193
int _wasmfs_fchmod (int fd, mode_t mode) { return __syscall_fchmod (fd, mode); }
194
194
195
- int _wasmfs_lchmod (char * path, mode_t mode) {
195
+ int _wasmfs_lchmod (const char * path, mode_t mode) {
196
196
return __syscall_fchmodat2 (
197
197
AT_FDCWD, (intptr_t )path, mode, AT_SYMLINK_NOFOLLOW);
198
198
}
@@ -206,7 +206,7 @@ int _wasmfs_llseek(int fd, off_t offset, int whence) {
206
206
return newOffset;
207
207
}
208
208
209
- int _wasmfs_rename (char * oldpath, char * newpath) {
209
+ int _wasmfs_rename (const char * oldpath, const char * newpath) {
210
210
return __syscall_renameat (
211
211
AT_FDCWD, (intptr_t )oldpath, AT_FDCWD, (intptr_t )newpath);
212
212
}
@@ -237,7 +237,7 @@ int _wasmfs_pread(int fd, void* buf, size_t count, off_t offset) {
237
237
return numBytes;
238
238
}
239
239
240
- int _wasmfs_truncate (char * path, off_t length) {
240
+ int _wasmfs_truncate (const char * path, off_t length) {
241
241
return __syscall_truncate64 ((intptr_t )path, length);
242
242
}
243
243
@@ -259,7 +259,7 @@ int _wasmfs_munmap(void* addr, size_t length) {
259
259
return __syscall_munmap ((intptr_t )addr, length);
260
260
}
261
261
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) {
263
263
struct timespec times[2 ];
264
264
times[0 ].tv_sec = atime_ms / 1000 ;
265
265
times[0 ].tv_nsec = (atime_ms % 1000 ) * 1000000 ;
@@ -269,18 +269,18 @@ int _wasmfs_utime(char* path, long atime_ms, long mtime_ms) {
269
269
return __syscall_utimensat (AT_FDCWD, (intptr_t )path, (intptr_t )times, 0 );
270
270
}
271
271
272
- int _wasmfs_stat (char * path, struct stat * statBuf) {
272
+ int _wasmfs_stat (const char * path, struct stat * statBuf) {
273
273
return __syscall_stat64 ((intptr_t )path, (intptr_t )statBuf);
274
274
}
275
275
276
- int _wasmfs_lstat (char * path, struct stat * statBuf) {
276
+ int _wasmfs_lstat (const char * path, struct stat * statBuf) {
277
277
return __syscall_lstat64 ((intptr_t )path, (intptr_t )statBuf);
278
278
}
279
279
280
280
// The legacy JS API requires a mountpoint to already exist, so WasmFS will
281
281
// attempt to remove the target directory if it exists before replacing it with
282
282
// a mounted directory.
283
- int _wasmfs_mount (char * path, ::backend_t created_backend) {
283
+ int _wasmfs_mount (const char * path, ::backend_t created_backend) {
284
284
int err = __syscall_rmdir ((intptr_t )path);
285
285
286
286
// 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) {
296
296
// ENOENT - if nothing exists there
297
297
// EISDIR - if it is a directory
298
298
// EEXIST - if it is a normal file
299
- int _wasmfs_identify (char * path) {
299
+ int _wasmfs_identify (const char * path) {
300
300
struct stat file;
301
301
int err = 0 ;
302
302
err = stat (path, &file);
@@ -315,7 +315,7 @@ struct wasmfs_readdir_state {
315
315
struct dirent ** entries;
316
316
};
317
317
318
- struct wasmfs_readdir_state * _wasmfs_readdir_start (char * path) {
318
+ struct wasmfs_readdir_state * _wasmfs_readdir_start (const char * path) {
319
319
struct dirent ** entries;
320
320
int nentries = scandir (path, &entries, NULL , alphasort);
321
321
if (nentries == -1 ) {
0 commit comments