wcstok_s() differs from wcstok() just in:
- validation of _Context and _Delim arguments
- setting errno for invalid arguments
- calling exception handler for invalid arguments
So split wcstok_s() and wcstok() into two functions.
Do not set errno in wcstok() function.
Call invalid argument exception handler in wcstok_s() function.
---
mingw-w64-crt/Makefile.am | 3 +++
mingw-w64-crt/secapi/wcstok_s.c | 24 ++++++++++++++++++++++++
mingw-w64-crt/string/wcstok.c | 11 +++--------
3 files changed, 30 insertions(+), 8 deletions(-)
create mode 100644 mingw-w64-crt/secapi/wcstok_s.c
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index dc98a298ce1e..c800fe70b67f 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -588,6 +588,7 @@ src_msvcrt32=\
misc/wcsnlen.c \
misc/wcstoimax.c \
misc/wcstoumax.c \
+ secapi/wcstok_s.c \
stdio/_fseeki64.c \
stdio/_fstat64.c \
stdio/_fstat64i32.c \
@@ -646,6 +647,7 @@ src_msvcrt64=\
misc/strnlen.c \
misc/wassert.c \
misc/wcsnlen.c \
+ secapi/wcstok_s.c \
stdio/_fseeki64.c \
stdio/_fstat32.c \
stdio/_fstat32i64.c \
@@ -924,6 +926,7 @@ src_pre_msvcr80=\
misc/wassert.c \
misc/wcsnlen.c \
secapi/getenv_s.c \
+ secapi/wcstok_s.c \
stdio/_fseeki64.c \
stdio/_fstat64i32.c \
stdio/_ftelli64.c \
diff --git a/mingw-w64-crt/secapi/wcstok_s.c b/mingw-w64-crt/secapi/wcstok_s.c
new file mode 100644
index 000000000000..e8040090003b
--- /dev/null
+++ b/mingw-w64-crt/secapi/wcstok_s.c
@@ -0,0 +1,24 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <errno.h>
+#include <wchar.h>
+
+wchar_t *__cdecl wcstok_s(wchar_t *_Str, const wchar_t *_Delim, wchar_t
**_Context)
+{
+ /* wcstok_s() differs from wcstok() just in:
+ * - validation of _Context and _Delim arguments
+ * - setting errno for invalid arguments
+ * - calling exception handler for invalid arguments
+ */
+ if (!_Context || !_Delim || (!_Str && !*_Context)) {
+ errno = EINVAL;
+ _invalid_parameter_noinfo();
+ return NULL;
+ }
+ return wcstok(_Str, _Delim, _Context);
+}
+wchar_t *(__cdecl *__MINGW_IMP_SYMBOL(wcstok_s))(wchar_t *, const wchar_t *,
wchar_t **) = wcstok_s;
diff --git a/mingw-w64-crt/string/wcstok.c b/mingw-w64-crt/string/wcstok.c
index 598d8ed57bf2..f411936741f5 100644
--- a/mingw-w64-crt/string/wcstok.c
+++ b/mingw-w64-crt/string/wcstok.c
@@ -21,13 +21,11 @@
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <errno.h>
#include <wchar.h>
-wchar_t *__cdecl wcstok_s(wchar_t *restrict s, const wchar_t *restrict sep,
wchar_t **restrict p)
+wchar_t *__cdecl wcstok(wchar_t *restrict s, const wchar_t *restrict sep,
wchar_t **restrict p)
{
- if (!p || !sep) { errno = EINVAL; return NULL; } /* added for wcstok_s */
- if (!s && !(s = *p)) { errno = EINVAL; return NULL; }
+ if (!s && !(s = *p)) return NULL;
s += wcsspn(s, sep);
if (!*s) return *p = NULL;
*p = s + wcscspn(s, sep);
@@ -35,7 +33,4 @@ wchar_t *__cdecl wcstok_s(wchar_t *restrict s, const wchar_t
*restrict sep, wcha
else *p = 0;
return s;
}
-wchar_t *(__cdecl *__MINGW_IMP_SYMBOL(wcstok_s))(wchar_t *restrict, const
wchar_t *restrict, wchar_t **restrict) = wcstok_s;
-
-wchar_t * __attribute__ ((alias ("wcstok_s"))) __cdecl wcstok (wchar_t
*restrict, const wchar_t *restrict, wchar_t **restrict);
-extern wchar_t * (__cdecl * __attribute__((alias
(__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(wcstok_s)))))
__MINGW_IMP_SYMBOL(wcstok))(wchar_t *restrict, const wchar_t *restrict, wchar_t
**restrict);
+wchar_t *(__cdecl *__MINGW_IMP_SYMBOL(wcstok))(wchar_t *restrict, const
wchar_t *restrict, wchar_t **restrict) = wcstok;
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public