Skip to content

Commit a7fd653

Browse files
authored
Add bh_strtok_r function (#4790)
1 parent 23df0d4 commit a7fd653

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

core/iwasm/common/wasm_runtime_common.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3909,13 +3909,8 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
39093909
goto fail;
39103910
}
39113911

3912-
#ifdef BH_PLATFORM_WINDOWS
3913-
address = strtok_s(cp, "/", &nextptr);
3914-
mask = strtok_s(NULL, "/", &nextptr);
3915-
#else
3916-
address = strtok_r(cp, "/", &nextptr);
3917-
mask = strtok_r(NULL, "/", &nextptr);
3918-
#endif
3912+
address = bh_strtok_r(cp, "/", &nextptr);
3913+
mask = bh_strtok_r(NULL, "/", &nextptr);
39193914

39203915
if (!mask) {
39213916
snprintf(error_buf, error_buf_size,

core/shared/utils/bh_common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ wa_strdup(const char *s)
166166
return s1;
167167
}
168168

169+
char *
170+
bh_strtok_r(char *str, const char *delim, char **saveptr)
171+
{
172+
#if !(defined(_WIN32) || defined(_WIN32_))
173+
return strtok_r(str, delim, saveptr);
174+
#else
175+
return strtok_s(str, delim, saveptr);
176+
#endif
177+
}
178+
169179
#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
170180
int
171181
bh_system(const char *cmd)

core/shared/utils/bh_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ bh_strdup(const char *s);
6666
char *
6767
wa_strdup(const char *s);
6868

69+
char *
70+
bh_strtok_r(char *str, const char *delim, char **saveptr);
71+
6972
#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
7073
/* Executes a system command in bash/cmd.exe */
7174
int

0 commit comments

Comments
 (0)