libc/wchar: Add wcschr() - scc - simple c99 compiler
 (HTM) git clone git://git.simple-cc.org/scc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 8a6918d48bb8ecbc1c2af2c72b2e89a3df3a999b
 (DIR) parent 4ac2c9373b1004d4176807d0b106c97cbdab8163
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Tue, 25 Mar 2025 21:26:58 +0100
       
       libc/wchar: Add wcschr()
       
       Diffstat:
         M src/libc/objs/common-objs.mk        |       1 +
         A src/libc/wchar/wcschr.c             |      11 +++++++++++
         M tests/libc/execute/.gitignore       |       1 +
         A tests/libc/execute/0057-wcschr.c    |      44 +++++++++++++++++++++++++++++++
         M tests/libc/execute/libc-tests.lst   |       1 +
       
       5 files changed, 58 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk
       @@ -133,6 +133,7 @@ COMMON_OBJS =\
                wchar/wcscpy.$O\
                wchar/wcscat.$O\
                wchar/wcsncat.$O\
       +        wchar/wcschr.$O\
                wchar/wcsrtombs.$O\
                wchar/wcwidth.$O\
                wchar/wmemchr.$O\
 (DIR) diff --git a/src/libc/wchar/wcschr.c b/src/libc/wchar/wcschr.c
       @@ -0,0 +1,11 @@
       +#include <wchar.h>
       +
       +#undef wcschr
       +
       +wchar_t *
       +wcschr(const wchar_t *s, wchar_t c)
       +{
       +        while (*s && *s != c)
       +                ++s;
       +        return (*s == c) ? (wchar_t *) s : NULL;
       +}
 (DIR) diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
       @@ -53,4 +53,5 @@
        0054-wcsncpy
        0055-wcscat
        0056-wcsncat
       +0057-wcschr
        test.log
 (DIR) diff --git a/tests/libc/execute/0057-wcschr.c b/tests/libc/execute/0057-wcschr.c
       @@ -0,0 +1,44 @@
       +#include <assert.h>
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +/*
       +output:
       +testing
       +done
       +end:
       +*/
       +
       +int
       +main()
       +{
       +        wchar_t *p, buf[] = L"abcad";
       +
       +        puts("testing");
       +
       +        p = wcschr(buf, 0);
       +        assert(p == buf+5);
       +        assert(*p == '\0');
       +
       +        p = wcschr(buf, 'a');
       +        assert(p == buf);
       +        assert(*p == 'a');
       +
       +        p = wcschr(buf, 'd');
       +        assert(p == buf+4);
       +        assert(*p == 'd');
       +
       +        p = wcschr(buf, 'c');
       +        assert(p == buf+2);
       +        assert(*p == 'c');
       +
       +        p = wcschr(buf, 'h');
       +        assert(p == NULL);
       +
       +        p = wcschr("", 'a');
       +        assert(p == NULL);
       +
       +        puts("done");
       +
       +        return 0;
       +}
 (DIR) diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -52,3 +52,4 @@
        0054-wcsncpy
        0055-wcscat
        0056-wcsncat
       +0057-wcschr