Skip to content

Commit 58f34ff

Browse files
authored
[WasmFS] Simplify thread local usage in js_api.cpp. NFC (#23824)
1 parent 8cbb965 commit 58f34ff

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

system/lib/wasmfs/js_api.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,13 @@ int _wasmfs_symlink(char* old_path, char* new_path) {
150150
}
151151

152152
intptr_t _wasmfs_readlink(char* path) {
153-
static thread_local void* readBuf = nullptr;
154-
readBuf = realloc(readBuf, PATH_MAX);
153+
static thread_local char* readBuf = (char*)malloc(PATH_MAX);
155154
int bytes =
156155
__syscall_readlinkat(AT_FDCWD, (intptr_t)path, (intptr_t)readBuf, PATH_MAX);
157156
if (bytes < 0) {
158157
return bytes;
159158
}
160-
((char*)readBuf)[bytes] = '\0';
159+
readBuf[bytes] = '\0';
161160
return (intptr_t)readBuf;
162161
}
163162

@@ -350,9 +349,8 @@ void _wasmfs_readdir_finish(struct wasmfs_readdir_state* state) {
350349

351350
char* _wasmfs_get_cwd(void) {
352351
// TODO: PATH_MAX is 4K atm, so it might be good to reduce this somehow.
353-
static thread_local void* path = nullptr;
354-
path = realloc(path, PATH_MAX);
355-
return getcwd((char*)path, PATH_MAX);
352+
static thread_local char* path = (char*)malloc(PATH_MAX);
353+
return getcwd(path, PATH_MAX);
356354
}
357355

358356
} // extern "C"

0 commit comments

Comments
 (0)