From eb8f14bb6a42aa36ad297916527fb9a5fae375cc Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 20 Nov 2019 20:40:50 +0300 Subject: [PATCH] added SDL_strtokr() as a replacement for POSIX strtok_r (bug #4046.) --- CMakeLists.txt | 4 +- Makefile.os2 | 4 +- Makefile.psp | 3 +- VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj | 1 + .../UWP_VS2015/SDL-UWP.vcxproj.filters | 3 + .../WinPhone81_VS2013/SDL-WinPhone81.vcxproj | 1 + .../SDL-WinPhone81.vcxproj.filters | 3 + .../WinRT81_VS2013/SDL-WinRT81.vcxproj | 1 + .../SDL-WinRT81.vcxproj.filters | 3 + VisualC/SDL/SDL.vcxproj | 1 + VisualC/SDL/SDL.vcxproj.filters | 1 + Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj | 10 ++ Xcode/SDL/SDL.xcodeproj/project.pbxproj | 8 ++ configure | 2 +- configure.ac | 2 +- include/SDL_config.h.cmake | 2 + include/SDL_config.h.in | 2 + include/SDL_config_android.h | 1 + include/SDL_config_iphoneos.h | 1 + include/SDL_config_macosx.h | 1 + include/SDL_config_os2.h | 1 + include/SDL_config_windows.h | 4 + include/SDL_config_winrt.h | 1 + include/SDL_config_wiz.h | 1 + include/SDL_stdinc.h | 2 + src/dynapi/SDL_dynapi_overrides.h | 1 + src/dynapi/SDL_dynapi_procs.h | 1 + src/stdlib/SDL_strtokr.c | 103 ++++++++++++++++++ 28 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 src/stdlib/SDL_strtokr.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e8591d77..d731163e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -763,7 +763,7 @@ if(LIBC) wcslen wcscmp strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp - _stricmp _strnicmp sscanf + _stricmp _strnicmp strtok_s sscanf acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf) @@ -797,7 +797,7 @@ if(LIBC) foreach(_FN strtod malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat - _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa + _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp diff --git a/Makefile.os2 b/Makefile.os2 index 11ef3768c..700662577 100644 --- a/Makefile.os2 +++ b/Makefile.os2 @@ -1,4 +1,4 @@ -# Open Watcom makefile to build SDL2.dll for OS/2: +# Open Watcom makefile to build SDL2.dll for OS/2 # wmake -f Makefile.os2 LIBNAME = SDL2 @@ -33,7 +33,7 @@ MSRCS= e_atan2.c e_exp.c e_fmod.c e_log10.c e_log.c e_pow.c e_rem_pio2.c e_sqrt. s_atan.c s_copysign.c s_cos.c s_fabs.c s_floor.c s_scalbn.c s_sin.c s_tan.c SRCS = SDL.c SDL_assert.c SDL_error.c SDL_log.c SDL_dataqueue.c SDL_hints.c -SRCS+= SDL_getenv.c SDL_iconv.c SDL_malloc.c SDL_qsort.c SDL_stdlib.c SDL_string.c +SRCS+= SDL_getenv.c SDL_iconv.c SDL_malloc.c SDL_qsort.c SDL_stdlib.c SDL_string.c SDL_strtokr.c SRCS+= SDL_cpuinfo.c SDL_atomic.c SDL_spinlock.c SDL_thread.c SDL_timer.c SRCS+= SDL_rwops.c SDL_power.c SRCS+= SDL_audio.c SDL_audiocvt.c SDL_audiodev.c SDL_audiotypecvt.c SDL_mixer.c SDL_wave.c diff --git a/Makefile.psp b/Makefile.psp index de0e50e2f..16c540023 100644 --- a/Makefile.psp +++ b/Makefile.psp @@ -50,6 +50,7 @@ OBJS= src/SDL.o \ src/stdlib/SDL_qsort.o \ src/stdlib/SDL_stdlib.o \ src/stdlib/SDL_string.o \ + src/stdlib/SDL_strtokr.o \ src/thread/SDL_thread.o \ src/thread/generic/SDL_systls.o \ src/thread/psp/SDL_syssem.o \ @@ -78,7 +79,7 @@ OBJS= src/SDL.o \ src/video/psp/SDL_pspevents.o \ src/video/psp/SDL_pspvideo.o \ src/video/psp/SDL_pspgl.o \ - src/video/psp/SDL_pspmouse.o \ + src/video/psp/SDL_pspmouse.o INCDIR = ./include CFLAGS = -g -O2 -G0 -Wall -D__PSP__ -DHAVE_OPENGL diff --git a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj index ede896fe3..50a9738c5 100644 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj @@ -285,6 +285,7 @@ + diff --git a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters index 7a26d851a..a6b12f13b 100644 --- a/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters +++ b/VisualC-WinRT/UWP_VS2015/SDL-UWP.vcxproj.filters @@ -626,6 +626,9 @@ Source Files + + Source Files + Source Files diff --git a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj index a7df73bd4..8a5682d9c 100644 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj @@ -251,6 +251,7 @@ + diff --git a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters index dba8edd3f..8a84da57d 100644 --- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters +++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters @@ -593,6 +593,9 @@ Source Files + + Source Files + Source Files diff --git a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj index 84b06d5d0..1fe2c0f97 100644 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj @@ -283,6 +283,7 @@ + diff --git a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters index 6a52b1caa..e9dcce5be 100644 --- a/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters +++ b/VisualC-WinRT/WinRT81_VS2013/SDL-WinRT81.vcxproj.filters @@ -611,6 +611,9 @@ Source Files + + Source Files + Source Files diff --git a/VisualC/SDL/SDL.vcxproj b/VisualC/SDL/SDL.vcxproj index 3a8a15196..37cec44c9 100644 --- a/VisualC/SDL/SDL.vcxproj +++ b/VisualC/SDL/SDL.vcxproj @@ -484,6 +484,7 @@ + diff --git a/VisualC/SDL/SDL.vcxproj.filters b/VisualC/SDL/SDL.vcxproj.filters index f464c1a2c..76dc0b566 100644 --- a/VisualC/SDL/SDL.vcxproj.filters +++ b/VisualC/SDL/SDL.vcxproj.filters @@ -426,6 +426,7 @@ + diff --git a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj index c863dc8f4..a805ca286 100644 --- a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj @@ -355,6 +355,10 @@ 56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; }; 56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; }; 56F9D5601DF73BA400C15B5D /* SDL_dataqueue.c in Sources */ = {isa = PBXBuildFile; fileRef = 566726431DF72CF5001DD3DB /* SDL_dataqueue.c */; }; + 63CC93C723849391002A5C54 /* SDL_strtokr.c in Sources */ = {isa = PBXBuildFile; fileRef = 63CC93C623849391002A5C54 /* SDL_strtokr.c */; }; + 63CC93C823849391002A5C54 /* SDL_strtokr.c in Sources */ = {isa = PBXBuildFile; fileRef = 63CC93C623849391002A5C54 /* SDL_strtokr.c */; }; + 63CC93C923849391002A5C54 /* SDL_strtokr.c in Sources */ = {isa = PBXBuildFile; fileRef = 63CC93C623849391002A5C54 /* SDL_strtokr.c */; }; + 63CC93CA23849391002A5C54 /* SDL_strtokr.c in Sources */ = {isa = PBXBuildFile; fileRef = 63CC93C623849391002A5C54 /* SDL_strtokr.c */; }; 93CB792313FC5E5200BD3E05 /* SDL_uikitviewcontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = 93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */; }; 93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */; }; A704172E20F7E74800A82227 /* controller_type.h in Headers */ = {isa = PBXBuildFile; fileRef = A704172D20F7E74800A82227 /* controller_type.h */; }; @@ -963,6 +967,7 @@ 56EA86FA13E9EC2B002E47EB /* SDL_coreaudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_coreaudio.h; sourceTree = ""; }; 56ED04E0118A8EE200A56AA6 /* SDL_power.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_power.c; sourceTree = ""; }; 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_syspower.m; sourceTree = ""; }; + 63CC93C623849391002A5C54 /* SDL_strtokr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_strtokr.c; sourceTree = ""; }; 93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitviewcontroller.h; sourceTree = ""; }; 93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_uikitviewcontroller.m; sourceTree = ""; }; A704172D20F7E74800A82227 /* controller_type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = controller_type.h; sourceTree = ""; }; @@ -1491,6 +1496,7 @@ FD3F4A6F0DEA620800C5B771 /* stdlib */ = { isa = PBXGroup; children = ( + 63CC93C623849391002A5C54 /* SDL_strtokr.c */, FD3F4A700DEA620800C5B771 /* SDL_getenv.c */, FD3F4A710DEA620800C5B771 /* SDL_iconv.c */, FD3F4A720DEA620800C5B771 /* SDL_malloc.c */, @@ -2568,6 +2574,7 @@ 52ED1E56222889500061FCE0 /* SDL_gamecontroller.c in Sources */, 52ED1E57222889500061FCE0 /* SDL_systls.c in Sources */, 52ED1E58222889500061FCE0 /* SDL_sysfilesystem.m in Sources */, + 63CC93C823849391002A5C54 /* SDL_strtokr.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2696,6 +2703,7 @@ F3E3C7452241389A007D243C /* SDL_gamecontroller.c in Sources */, F3E3C7462241389A007D243C /* SDL_systls.c in Sources */, F3E3C7472241389A007D243C /* SDL_sysfilesystem.m in Sources */, + 63CC93CA23849391002A5C54 /* SDL_strtokr.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2822,6 +2830,7 @@ FAB598BD1BB5C31600BE72C5 /* SDL_hints.c in Sources */, FAB598BE1BB5C31600BE72C5 /* SDL_log.c in Sources */, FAB598BF1BB5C31600BE72C5 /* SDL.c in Sources */, + 63CC93C923849391002A5C54 /* SDL_strtokr.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2942,6 +2951,7 @@ AA0AD06216647BBB00CE5896 /* SDL_gamecontroller.c in Sources */, AA0F8495178D5F1A00823F9D /* SDL_systls.c in Sources */, 56C181E217C44D7A00406AE3 /* SDL_sysfilesystem.m in Sources */, + 63CC93C723849391002A5C54 /* SDL_strtokr.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index 320680df0..be8c94e81 100644 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -456,6 +456,9 @@ 5C2EF6FE1FC9EE65003F5197 /* SDL_egl.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C2EF6F51FC9EE35003F5197 /* SDL_egl.c */; }; 5C2EF6FF1FC9EE65003F5197 /* SDL_rect_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C2EF6F41FC9EE34003F5197 /* SDL_rect_c.h */; }; 5C2EF7011FC9EF10003F5197 /* SDL_egl.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C2EF7001FC9EF0F003F5197 /* SDL_egl.h */; }; + 63994BE7238492D000F9C268 /* SDL_strtokr.c in Sources */ = {isa = PBXBuildFile; fileRef = 63994BE6238492D000F9C268 /* SDL_strtokr.c */; }; + 63994BE8238492D000F9C268 /* SDL_strtokr.c in Sources */ = {isa = PBXBuildFile; fileRef = 63994BE6238492D000F9C268 /* SDL_strtokr.c */; }; + 63994BE9238492D000F9C268 /* SDL_strtokr.c in Sources */ = {isa = PBXBuildFile; fileRef = 63994BE6238492D000F9C268 /* SDL_strtokr.c */; }; A704170920F09A9800A82227 /* hid.c in Sources */ = {isa = PBXBuildFile; fileRef = A704170820F09A9800A82227 /* hid.c */; }; A704170A20F09A9800A82227 /* hid.c in Sources */ = {isa = PBXBuildFile; fileRef = A704170820F09A9800A82227 /* hid.c */; }; A704170B20F09A9800A82227 /* hid.c in Sources */ = {isa = PBXBuildFile; fileRef = A704170820F09A9800A82227 /* hid.c */; }; @@ -1152,6 +1155,7 @@ 5C2EF6F51FC9EE35003F5197 /* SDL_egl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_egl.c; sourceTree = ""; }; 5C2EF6F61FC9EE35003F5197 /* SDL_egl_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_egl_c.h; sourceTree = ""; }; 5C2EF7001FC9EF0F003F5197 /* SDL_egl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_egl.h; sourceTree = ""; }; + 63994BE6238492D000F9C268 /* SDL_strtokr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_strtokr.c; sourceTree = ""; }; A704170820F09A9800A82227 /* hid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hid.c; sourceTree = ""; }; A704170D20F09AC800A82227 /* SDL_hidapijoystick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapijoystick.c; sourceTree = ""; }; A704170E20F09AC800A82227 /* SDL_hidapijoystick_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_hidapijoystick_c.h; sourceTree = ""; }; @@ -1636,6 +1640,7 @@ 04BDFE5D12E6671700899322 /* stdlib */ = { isa = PBXGroup; children = ( + 63994BE6238492D000F9C268 /* SDL_strtokr.c */, 04BDFE5E12E6671700899322 /* SDL_getenv.c */, 04BDFE5F12E6671700899322 /* SDL_iconv.c */, 04BDFE6012E6671700899322 /* SDL_malloc.c */, @@ -2812,6 +2817,7 @@ AA0F8491178D5ECC00823F9D /* SDL_systls.c in Sources */, D55A1B82179F262300625D7C /* SDL_cocoamousetap.m in Sources */, 567E2F1C17C44BB2005F1892 /* SDL_sysfilesystem.m in Sources */, + 63994BE7238492D000F9C268 /* SDL_strtokr.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2950,6 +2956,7 @@ AA0F8492178D5ECC00823F9D /* SDL_systls.c in Sources */, D55A1B84179F263600625D7C /* SDL_cocoamousetap.m in Sources */, DB0F490817CA5292008798C5 /* SDL_sysfilesystem.m in Sources */, + 63994BE8238492D000F9C268 /* SDL_strtokr.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3088,6 +3095,7 @@ AA0F8493178D5ECC00823F9D /* SDL_systls.c in Sources */, D55A1B83179F263500625D7C /* SDL_cocoamousetap.m in Sources */, DB0F490A17CA5293008798C5 /* SDL_sysfilesystem.m in Sources */, + 63994BE9238492D000F9C268 /* SDL_strtokr.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/configure b/configure index a4f7b7459..0ece9b9ba 100755 --- a/configure +++ b/configure @@ -16978,7 +16978,7 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi - for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcscmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval poll _Exit + for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcscmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval poll _Exit do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index 186229ab0..f310caabd 100644 --- a/configure.ac +++ b/configure.ac @@ -335,7 +335,7 @@ if test x$enable_libc = xyes; then AC_DEFINE(HAVE_MPROTECT, 1, [ ]) ]), ) - AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcscmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval poll _Exit) + AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcscmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval poll _Exit) AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"]) AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf) diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 34220f3ff..8224acad5 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -108,6 +108,8 @@ #cmakedefine HAVE_STRCHR 1 #cmakedefine HAVE_STRRCHR 1 #cmakedefine HAVE_STRSTR 1 +#cmakedefine HAVE_STRTOK_R 1 +#cmakedefine HAVE_STRTOK_S 1 #cmakedefine HAVE_ITOA 1 #cmakedefine HAVE__LTOA 1 #cmakedefine HAVE__UITOA 1 diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 5c7f89bef..f064ba6e9 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -111,6 +111,8 @@ #undef HAVE_STRCHR #undef HAVE_STRRCHR #undef HAVE_STRSTR +#undef HAVE_STRTOK_R +#undef HAVE_STRTOK_S #undef HAVE_ITOA #undef HAVE__LTOA #undef HAVE__UITOA diff --git a/include/SDL_config_android.h b/include/SDL_config_android.h index 8f5348605..9cb70bfef 100644 --- a/include/SDL_config_android.h +++ b/include/SDL_config_android.h @@ -71,6 +71,7 @@ #define HAVE_STRCHR 1 #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 +#define HAVE_STRTOK_R 1 #define HAVE_STRTOL 1 #define HAVE_STRTOUL 1 #define HAVE_STRTOLL 1 diff --git a/include/SDL_config_iphoneos.h b/include/SDL_config_iphoneos.h index 8137085ed..edfc03e2b 100644 --- a/include/SDL_config_iphoneos.h +++ b/include/SDL_config_iphoneos.h @@ -71,6 +71,7 @@ #define HAVE_STRCHR 1 #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 +#define HAVE_STRTOK_R 1 #define HAVE_STRTOL 1 #define HAVE_STRTOUL 1 #define HAVE_STRTOLL 1 diff --git a/include/SDL_config_macosx.h b/include/SDL_config_macosx.h index 2035f2d0c..22287dfc6 100644 --- a/include/SDL_config_macosx.h +++ b/include/SDL_config_macosx.h @@ -74,6 +74,7 @@ #define HAVE_STRCHR 1 #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 +#define HAVE_STRTOK_R 1 #define HAVE_STRTOL 1 #define HAVE_STRTOUL 1 #define HAVE_STRTOLL 1 diff --git a/include/SDL_config_os2.h b/include/SDL_config_os2.h index bc75b3a71..efb4e848d 100644 --- a/include/SDL_config_os2.h +++ b/include/SDL_config_os2.h @@ -110,6 +110,7 @@ #define HAVE_STRCHR 1 #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 +/* #undef HAVE_STRTOK_R */ #define HAVE_ITOA 1 #define HAVE__LTOA 1 #define HAVE__ULTOA 1 diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h index f8f73385c..a9576d8b0 100644 --- a/include/SDL_config_windows.h +++ b/include/SDL_config_windows.h @@ -117,6 +117,10 @@ typedef unsigned int uintptr_t; #define HAVE_STRCHR 1 #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 +/* #undef HAVE_STRTOK_R */ +#if defined(_MSC_VER) +#define HAVE_STRTOK_S 1 +#endif /* These functions have security warnings, so we won't use them */ /* #undef HAVE__LTOA */ /* #undef HAVE__ULTOA */ diff --git a/include/SDL_config_winrt.h b/include/SDL_config_winrt.h index 8eeeb5127..cb85b234a 100644 --- a/include/SDL_config_winrt.h +++ b/include/SDL_config_winrt.h @@ -130,6 +130,7 @@ typedef unsigned int uintptr_t; #define HAVE_STRCHR 1 #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 +#define HAVE_STRTOK_S 1 //#define HAVE_ITOA 1 // TODO, WinRT: consider using _itoa_s instead //#define HAVE__LTOA 1 // TODO, WinRT: consider using _ltoa_s instead //#define HAVE__ULTOA 1 // TODO, WinRT: consider using _ultoa_s instead diff --git a/include/SDL_config_wiz.h b/include/SDL_config_wiz.h index c5eb9b34b..724c55fc0 100644 --- a/include/SDL_config_wiz.h +++ b/include/SDL_config_wiz.h @@ -67,6 +67,7 @@ #define HAVE_STRCHR 1 #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 +#define HAVE_STRTOK_R 1 #define HAVE_STRTOL 1 #define HAVE_STRTOUL 1 #define HAVE_STRTOLL 1 diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index a95700af2..dd2c8734b 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -470,6 +470,7 @@ extern DECLSPEC char *SDLCALL SDL_strlwr(char *str); extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c); extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c); extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle); +extern DECLSPEC char *SDLCALL SDL_strtokr(char *s1, const char *s2, char **saveptr); extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str); extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix); @@ -584,6 +585,7 @@ extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode, #define SDL_strchr strchr #define SDL_strrchr strrchr #define SDL_strstr strstr +#define SDL_strtokr strtok_r #define SDL_strcmp strcmp #define SDL_strncmp strncmp #define SDL_strcasecmp strcasecmp diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index c4d548dba..0bf1baad8 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -728,3 +728,4 @@ #define SDL_Metal_DestroyView SDL_Metal_DestroyView_REAL #define SDL_LockTextureToSurface SDL_LockTextureToSurface_REAL #define SDL_HasARMSIMD SDL_HasARMSIMD_REAL +#define SDL_strtokr SDL_strtokr_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 718e3bed3..654092164 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -784,3 +784,4 @@ SDL_DYNAPI_PROC(SDL_MetalView,SDL_Metal_CreateView,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(void,SDL_Metal_DestroyView,(SDL_MetalView a),(a),) SDL_DYNAPI_PROC(int,SDL_LockTextureToSurface,(SDL_Texture *a, const SDL_Rect *b, SDL_Surface **c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_bool,SDL_HasARMSIMD,(void),(),return) +SDL_DYNAPI_PROC(char*,SDL_strtokr,(char *a, const char *b, char **c),(a,b,c),return) diff --git a/src/stdlib/SDL_strtokr.c b/src/stdlib/SDL_strtokr.c new file mode 100644 index 000000000..b020b6436 --- /dev/null +++ b/src/stdlib/SDL_strtokr.c @@ -0,0 +1,103 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2019 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#if defined(__clang_analyzer__) +#define SDL_DISABLE_ANALYZE_MACROS 1 +#endif + +#include "../SDL_internal.h" + +#include "SDL_stdinc.h" + +char *SDL_strtokr(char *s1, const char *s2, char **ptr) +{ +#if defined(HAVE_STRTOK_R) + return strtok_r(s1, s2, ptr); + +#elif defined(_MSC_VER) && defined(HAVE_STRTOK_S) + return strtok_s(s1, s2, ptr); + +#else /* SDL implementation */ +/* + * Adapted from _PDCLIB_strtok() of PDClib library at + * https://github.com/DevSolar/pdclib.git + * + * The code was under CC0 license: + * https://creativecommons.org/publicdomain/zero/1.0/legalcode : + * + * No Copyright + * + * The person who associated a work with this deed has dedicated the + * work to the public domain by waiving all of his or her rights to + * the work worldwide under copyright law, including all related and + * neighboring rights, to the extent allowed by law. + * + * You can copy, modify, distribute and perform the work, even for + * commercial purposes, all without asking permission. See Other + * Information below. + */ + const char *p = s2; + + if (!s2 || !ptr || (!s1 && !*ptr)) return NULL; + + if (s1 != NULL) { /* new string */ + *ptr = s1; + } else { /* old string continued */ + if (*ptr == NULL) { + /* No old string, no new string, nothing to do */ + return NULL; + } + s1 = *ptr; + } + + /* skip leading s2 characters */ + while (*p && *s1) { + if (*s1 == *p) { + /* found separator; skip and start over */ + ++s1; + p = s2; + continue; + } + ++p; + } + + if (! *s1) { /* no more to parse */ + *ptr = s1; + return NULL; + } + + /* skipping non-s2 characters */ + *ptr = s1; + while (**ptr) { + p = s2; + while (*p) { + if (**ptr == *p++) { + /* found separator; overwrite with '\0', position *ptr, return */ + *((*ptr)++) = '\0'; + return s1; + } + } + ++(*ptr); + } + + /* parsed to end of string */ + return s1; +#endif +}