URI:
       libc: Add wcstok - scc - simple c99 compiler
  HTML git clone git://git.simple-cc.org/scc
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit 005f4c376c05bd22e21761cf063ea76fb9338dc1
   DIR parent b2eb6e5269977992d88d388ff30a078aa9101a42
  HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Sat,  3 Jan 2026 18:55:53 +0100
       
       libc: Add wcstok
       
       Diffstat:
         M src/libc/objs/common-objs.mk        |       1 +
         A src/libc/wchar/wcstok.c             |      31 +++++++++++++++++++++++++++++++
         M tests/libc/execute/.gitignore       |       1 +
         A tests/libc/execute/0064-wcstok.c    |      61 +++++++++++++++++++++++++++++++
         M tests/libc/execute/libc-tests.lst   |       1 +
       
       5 files changed, 95 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk
       @@ -143,6 +143,7 @@ COMMON_OBJS =\
                wchar/wcsrtombs.$O\
                wchar/wcsspn.$O\
                wchar/wcsstr.$O\
       +        wchar/wcstok.$O\
                wchar/wcsxfrm.$O\
                wchar/wcwidth.$O\
                wchar/wmemchr.$O\
   DIR diff --git a/src/libc/wchar/wcstok.c b/src/libc/wchar/wcstok.c
       @@ -0,0 +1,31 @@
       +#include <wchar.h>
       +
       +#undef wcstok
       +
       +wchar_t *
       +wcstok(wchar_t * restrict s1, const wchar_t * restrict s2,
       +       wchar_t **restrict ptr)
       +{
       +        wchar_t *line;
       +
       +        if (s1)
       +                line = s1;
       +        else
       +                line = *ptr;
       +
       +        if (!line)
       +                return NULL;
       +
       +        s1 = line + wcsspn(line, s2);
       +        if (*s1 == L'\0')
       +                return *ptr = NULL;
       +
       +        line = s1 + wcscspn(s1, s2);
       +        if (*line == '\0')
       +                line = NULL;
       +        else
       +                *line++ = L'\0';
       +        *ptr = line;
       +
       +        return s1;
       +}
   DIR diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
       @@ -60,4 +60,5 @@
        0061-wcsspn
        0062-wcscspn
        0063-wcspbrk
       +0064-wcstok
        test.log
   DIR diff --git a/tests/libc/execute/0064-wcstok.c b/tests/libc/execute/0064-wcstok.c
       @@ -0,0 +1,61 @@
       +#include <assert.h>
       +#include <stdio.h>
       +#include <stdlib.h>
       +#include <wchar.h>
       +
       +/*
       +output:
       +testing
       +test1
       +one
       +two
       +three
       +four
       +test2
       +one
       +three
       +test3
       +one
       +done
       +end:
       +*/
       +
       +void
       +test(char *msg, wchar_t *fmt)
       +{
       +        wchar_t *s, *p, buff[50];
       +
       +        puts(msg);
       +
       +        wcscpy(buff, fmt);
       +        for (s = wcstok(buff, L"-+", &p); s; s = wcstok(NULL, L"+-", &p)) {
       +                switch (*s) {
       +                case L'1':
       +                        puts("one");
       +                        break;
       +                case L'2':
       +                        puts("two");
       +                        break;
       +                case L'3':
       +                        puts("three");
       +                        break;
       +                case L'4':
       +                        puts("four");
       +                        break;
       +                default:
       +                        puts("error");
       +                        break;
       +                }
       +        }
       +}
       +
       +int
       +main()
       +{
       +        puts("testing");
       +        test("test1", L"-+1--2++3+-4");
       +        test("test2", L"1--+-+-+-3+-");
       +        test("test3", L"1");
       +        puts("done");
       +        return 0;
       +}
   DIR diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -59,3 +59,4 @@
        0061-wcsspn
        0062-wcscspn
        0063-wcspbrk
       +0064-wcstok