@@ -22,12 +22,12 @@ using namespace wasmfs;
22
22
23
23
extern " C" {
24
24
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);
26
26
27
27
// Copy the file specified by the pathname into JS.
28
28
// Return a pointer to the JS buffer in HEAPU8.
29
29
// The buffer will also contain the file length.
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, const char * data, size_t data_size) {
73
73
auto parsedParent = path::parseParent (pathname);
74
74
if (parsedParent.getError ()) {
75
75
return 0 ;
@@ -119,35 +119,35 @@ 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, mode_t mode) {
122
+ int _wasmfs_mkdir (const char * path, mode_t mode) {
123
123
return __syscall_mkdirat (AT_FDCWD, path, mode);
124
124
}
125
125
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); }
127
127
128
- int _wasmfs_open (char * path, int flags, mode_t mode) {
128
+ int _wasmfs_open (const char * path, int flags, mode_t mode) {
129
129
return __syscall_openat (AT_FDCWD, path, flags, mode);
130
130
}
131
131
132
132
int _wasmfs_allocate (int fd, off_t offset, off_t len) {
133
133
return __syscall_fallocate (fd, 0 , offset, len);
134
134
}
135
135
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) {
137
137
return __syscall_mknodat (AT_FDCWD, path, mode, dev);
138
138
}
139
139
140
- int _wasmfs_unlink (char * path) {
140
+ int _wasmfs_unlink (const char * path) {
141
141
return __syscall_unlinkat (AT_FDCWD, path, 0 );
142
142
}
143
143
144
- int _wasmfs_chdir (char * path) { return __syscall_chdir (path); }
144
+ int _wasmfs_chdir (const char * path) { return __syscall_chdir (path); }
145
145
146
- int _wasmfs_symlink (char * old_path, char * new_path) {
146
+ int _wasmfs_symlink (const char * old_path, const char * new_path) {
147
147
return __syscall_symlink (old_path, new_path);
148
148
}
149
149
150
- intptr_t _wasmfs_readlink (char * path) {
150
+ intptr_t _wasmfs_readlink (const char * path) {
151
151
static thread_local void * readBuf = nullptr ;
152
152
readBuf = realloc (readBuf, PATH_MAX);
153
153
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) {
183
183
return numBytes;
184
184
}
185
185
186
- int _wasmfs_chmod (char * path, mode_t mode) {
186
+ int _wasmfs_chmod (const char * path, mode_t mode) {
187
187
return __syscall_chmod (path, mode);
188
188
}
189
189
190
190
int _wasmfs_fchmod (int fd, mode_t mode) {
191
191
return __syscall_fchmod (fd, mode);
192
192
}
193
193
194
- int _wasmfs_lchmod (char * path, mode_t mode) {
194
+ int _wasmfs_lchmod (const char * path, mode_t mode) {
195
195
return __syscall_fchmodat (AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW);
196
196
}
197
197
@@ -204,7 +204,7 @@ int _wasmfs_llseek(int fd, off_t offset, int whence) {
204
204
return newOffset;
205
205
}
206
206
207
- int _wasmfs_rename (char * oldpath, char * newpath) {
207
+ int _wasmfs_rename (const char * oldpath, const char * newpath) {
208
208
return __syscall_renameat (AT_FDCWD, oldpath, AT_FDCWD, newpath);
209
209
};
210
210
@@ -234,7 +234,7 @@ int _wasmfs_pread(int fd, void *buf, size_t count, off_t offset) {
234
234
return numBytes;
235
235
}
236
236
237
- int _wasmfs_truncate (char * path, off_t length) {
237
+ int _wasmfs_truncate (const char * path, off_t length) {
238
238
return __syscall_truncate64 (path, length);
239
239
}
240
240
@@ -246,19 +246,19 @@ int _wasmfs_close(int fd) {
246
246
return __wasi_fd_close (fd);
247
247
}
248
248
249
- int _wasmfs_stat (char * path, struct stat * statBuf) {
249
+ int _wasmfs_stat (const char * path, struct stat * statBuf) {
250
250
return __syscall_stat64 (path, statBuf);
251
251
}
252
252
253
- int _wasmfs_lstat (char * path, struct stat * statBuf) {
253
+ int _wasmfs_lstat (const char * path, struct stat * statBuf) {
254
254
return __syscall_lstat64 (path, statBuf);
255
255
}
256
256
257
257
// Helper method that identifies what a path is:
258
258
// ENOENT - if nothing exists there
259
259
// EISDIR - if it is a directory
260
260
// EEXIST - if it is a normal file
261
- int _wasmfs_identify (char * path) {
261
+ int _wasmfs_identify (const char * path) {
262
262
struct stat file;
263
263
int err = 0 ;
264
264
err = stat (path, &file);
@@ -277,7 +277,7 @@ struct wasmfs_readdir_state {
277
277
struct dirent ** entries;
278
278
};
279
279
280
- struct wasmfs_readdir_state * _wasmfs_readdir_start (char * path) {
280
+ struct wasmfs_readdir_state * _wasmfs_readdir_start (const char * path) {
281
281
struct dirent ** entries;
282
282
int nentries = scandir (path, &entries, NULL , alphasort);
283
283
if (nentries == -1 ) {
0 commit comments