util/stringops: prefer strtok_r from libc
This commit is contained in:
parent
00dca36a59
commit
057f3f5571
3 changed files with 16 additions and 5 deletions
13
meson.build
13
meson.build
|
@ -256,9 +256,16 @@ config.set('TAISEI_BUILDCONF_HAVE_LONG_DOUBLE', cc.sizeof('long double') > 8)
|
|||
config.set('TAISEI_BUILDCONF_HAVE_POSIX', have_posix)
|
||||
config.set('TAISEI_BUILDCONF_HAVE_SINCOS', cc.has_function('sincos', dependencies : dep_m))
|
||||
|
||||
if config.get('TAISEI_BUILDCONF_HAVE_SINCOS')
|
||||
config.set('_GNU_SOURCE', true)
|
||||
endif
|
||||
use_gnu_funcs = false
|
||||
gnu_funcs = ['sincos', 'strtok_r']
|
||||
|
||||
foreach f : gnu_funcs
|
||||
have = cc.has_function(f, dependencies : dep_m)
|
||||
config.set('TAISEI_BUILDCONF_HAVE_@0@'.format(f.to_upper()), have)
|
||||
use_gnu_funcs = have or use_gnu_funcs
|
||||
endforeach
|
||||
|
||||
config.set('_GNU_SOURCE', use_gnu_funcs)
|
||||
|
||||
if host_machine.system() == 'emscripten'
|
||||
# Emscripten bug: https://github.com/emscripten-core/emscripten/issues/10072
|
||||
|
|
|
@ -208,6 +208,7 @@ char* ucs4_to_utf8_alloc(const uint32_t *ucs4) {
|
|||
return utf8;
|
||||
}
|
||||
|
||||
#ifndef TAISEI_BUILDCONF_HAVE_STRTOK_R
|
||||
/*
|
||||
* public domain strtok_r() by Charlie Gordon
|
||||
*
|
||||
|
@ -218,7 +219,7 @@ char* ucs4_to_utf8_alloc(const uint32_t *ucs4) {
|
|||
* (Declaration that it's public domain):
|
||||
* http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c
|
||||
*/
|
||||
char* strtok_r(char *str, const char *delim, char **nextp) {
|
||||
char *strtok_r(char *str, const char *delim, char **nextp) {
|
||||
char *ret;
|
||||
|
||||
if(str == NULL) {
|
||||
|
@ -241,6 +242,7 @@ char* strtok_r(char *str, const char *delim, char **nextp) {
|
|||
*nextp = str;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t filename_timestamp(char *buf, size_t buf_size, SystemTime systime) {
|
||||
assert(buf_size >= FILENAME_TIMESTAMP_MIN_BUF_SIZE);
|
||||
|
|
|
@ -32,8 +32,11 @@ INLINE attr_returns_allocated attr_nonnull(1) char *strdup(const char *str) {
|
|||
return memcpy(malloc(sz), str, sz);
|
||||
}
|
||||
|
||||
#ifndef TAISEI_BUILDCONF_HAVE_STRTOK_R
|
||||
#undef strtok_r
|
||||
#define strtok_r _ts_strtok_r
|
||||
char *strtok_r(char *str, const char *delim, char **nextp);
|
||||
#endif
|
||||
|
||||
#undef strcasecmp
|
||||
#define strcasecmp SDL_strcasecmp
|
||||
|
@ -46,7 +49,6 @@ void stralloc(char **dest, const char *src);
|
|||
char* strjoin(const char *first, ...) attr_sentinel attr_returns_allocated;
|
||||
char* vstrfmt(const char *fmt, va_list args) attr_returns_allocated;
|
||||
char* strfmt(const char *fmt, ...) attr_printf(1, 2) attr_returns_allocated;
|
||||
char* strtok_r(char *str, const char *delim, char **nextp);
|
||||
char* strappend(char **dst, char *src);
|
||||
char* strftimealloc(const char *fmt, const struct tm *timeinfo) attr_returns_allocated;
|
||||
void expand_escape_sequences(char *str);
|
||||
|
|
Loading…
Reference in a new issue