libc/wchar: Add wmemchr() - 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 bbb33960d11eacc45a1ea00d60bf46a39ae9693b
 (DIR) parent 3b42911841f616a37e3fa7bd5f4ad7177ce959cf
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Tue, 25 Mar 2025 18:30:34 +0100
       
       libc/wchar: Add wmemchr()
       
       Diffstat:
         M src/libc/objs/common-objs.mk        |       1 +
         A src/libc/wchar/wmemchr.c            |      11 +++++++++++
         M tests/libc/execute/.gitignore       |       1 +
         A tests/libc/execute/0049-wmemchr.c   |      25 +++++++++++++++++++++++++
         M tests/libc/execute/libc-tests.lst   |       1 +
       
       5 files changed, 39 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk
       @@ -133,5 +133,6 @@ COMMON_OBJS =\
                wchar/wcscpy.$O\
                wchar/wcsrtombs.$O\
                wchar/wcwidth.$O\
       +        wchar/wmemchr.$O\
                wchar/putwc.$O\
                wchar/_validutf8.$O\
 (DIR) diff --git a/src/libc/wchar/wmemchr.c b/src/libc/wchar/wmemchr.c
       @@ -0,0 +1,11 @@
       +#include <wchar.h>
       +
       +wchar_t *
       +wmemchr(const wchar_t *s, wchar_t c, size_t n)
       +{
       +        wchar_t *bp = (wchar_t *) s;
       +
       +        for ( ; n > 0 && *bp != c; n--)
       +                ++bp;
       +        return (n == 0) ? NULL : bp;
       +}
 (DIR) diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
       @@ -45,4 +45,5 @@
        0046-wcsncmp
        0047-wcscoll
        0048-wcscpy
       +0049-wmemchr
        test.log
 (DIR) diff --git a/tests/libc/execute/0049-wmemchr.c b/tests/libc/execute/0049-wmemchr.c
       @@ -0,0 +1,25 @@
       +#include <assert.h>
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +/*
       +output:
       +testing
       +done
       +end:
       +*/
       +
       +int
       +main()
       +{
       +        wchar_t buf[] = {0, 1, 2, 3, 4, 160};
       +
       +        puts("testing");
       +        assert(wmemchr(buf, 2, 6) == buf+2);
       +        assert(wmemchr(buf, 2, 0) == NULL);
       +        assert(wmemchr(buf, 150, 6) == NULL);
       +        assert(wmemchr(buf, 160, 6) == buf+5);
       +        puts("done");
       +
       +        return 0;
       +}
 (DIR) diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -44,3 +44,4 @@
        0046-wcsncmp
        0047-wcscoll
        0048-wcscpy
       +0049-wmemchr