URI:
       libc/wchar: Add wctob() - 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 9a60d2a80efcd85c85f90b1c0406c8fe3f324f5b
   DIR parent c4b7399c26bf3040f33b4760e162495d74d85d73
  HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Sun,  4 Jan 2026 20:29:39 +0100
       
       libc/wchar: Add wctob()
       
       Diffstat:
         M src/libc/objs/common-objs.mk        |       1 +
         M src/libc/wchar/Makefile             |       1 +
         A src/libc/wchar/wctob.c              |      14 ++++++++++++++
         M tests/libc/execute/.gitignore       |       1 +
         A tests/libc/execute/0066-wctob.c     |      22 ++++++++++++++++++++++
         M tests/libc/execute/libc-tests.lst   |       1 +
       
       6 files changed, 40 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk
       @@ -146,6 +146,7 @@ COMMON_OBJS =\
                wchar/wcsstr.$O\
                wchar/wcstok.$O\
                wchar/wcsxfrm.$O\
       +        wchar/wctob.$O\
                wchar/wcwidth.$O\
                wchar/wmemchr.$O\
                wchar/wmemcmp.$O\
   DIR diff --git a/src/libc/wchar/Makefile b/src/libc/wchar/Makefile
       @@ -13,6 +13,7 @@ OBJS =\
                wcrtomb.$O\
                wcslen.$O\
                wcsrtombs.$O\
       +        wctob.$O\
                wcwidth.$O\
                putwc.$O\
                _validutf8.$O\
   DIR diff --git a/src/libc/wchar/wctob.c b/src/libc/wchar/wctob.c
       @@ -0,0 +1,14 @@
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +#undef wctob
       +
       +int
       +wctob(wint_t wc)
       +{
       +        unsigned long w = wc;
       +
       +        if (wc == WEOF || w > 128)
       +                return EOF;
       +        return wc;
       +}
   DIR diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
       @@ -64,3 +64,4 @@
        0064-wcstok
        test.log
        0065-btowc
       +0066-wctob
   DIR diff --git a/tests/libc/execute/0066-wctob.c b/tests/libc/execute/0066-wctob.c
       @@ -0,0 +1,22 @@
       +#include <assert.h>
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +/*
       +output:
       +testing
       +done
       +end:
       +*/
       +
       +int
       +main(void)
       +{
       +        puts("testing");
       +        assert(wctob(L'a') == 'a');
       +        assert(wctob(WEOF) == -1);
       +        assert(wctob(134) == -1);
       +        puts("done");
       +
       +        return 0;
       +}
   DIR diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -62,3 +62,4 @@
        0063-wcspbrk
        0064-wcstok
        0065-btowc
       +0066-wctob