URI:
       libc/wchar: Add btowc() - 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 c4b7399c26bf3040f33b4760e162495d74d85d73
   DIR parent 534e0b91e27ad3cb37404d696cd1c0044a8ebe18
  HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Sun,  4 Jan 2026 20:17:51 +0100
       
       libc/wchar: Add btowc()
       
       Diffstat:
         M src/libc/objs/common-objs.mk        |       1 +
         M src/libc/wchar/Makefile             |       1 +
         A src/libc/wchar/btowc.c              |      14 ++++++++++++++
         M tests/libc/execute/.gitignore       |       1 +
         A tests/libc/execute/0065-btowc.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
       @@ -121,6 +121,7 @@ COMMON_OBJS =\
                time/strftime.$O\
                time/tz.$O\
                wchar/_validutf8.$O\
       +        wchar/btowc.$O\
                wchar/fputwc.$O\
                wchar/mbrlen.$O\
                wchar/mbrtowc.$O\
   DIR diff --git a/src/libc/wchar/Makefile b/src/libc/wchar/Makefile
       @@ -4,6 +4,7 @@ include $(PROJECTDIR)/scripts/rules.mk
        include ../rules.mk
        
        OBJS =\
       +        btowc.$O\
                fputwc.$O\
                mbrlen.$O\
                mbrtowc.$O\
   DIR diff --git a/src/libc/wchar/btowc.c b/src/libc/wchar/btowc.c
       @@ -0,0 +1,14 @@
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +#undef btowc
       +
       +wint_t
       +btowc(int ch)
       +{
       +        unsigned char c = ch;
       +
       +        if (ch == EOF || c >= 128)
       +                return WEOF;
       +        return ch;
       +}
   DIR diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
       @@ -63,3 +63,4 @@
        0063-wcspbrk
        0064-wcstok
        test.log
       +0065-btowc
   DIR diff --git a/tests/libc/execute/0065-btowc.c b/tests/libc/execute/0065-btowc.c
       @@ -0,0 +1,22 @@
       +#include <assert.h>
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +/*
       +output:
       +testing
       +done
       +end:
       +*/
       +
       +int
       +main(void)
       +{
       +        puts("testing");
       +        assert(btowc('a') == 'a');
       +        assert(btowc(EOF) == -1);
       +        assert(btowc('\x99') == -1);
       +        puts("done");
       +
       +        return 0;
       +}
   DIR diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -61,3 +61,4 @@
        0062-wcscspn
        0063-wcspbrk
        0064-wcstok
       +0065-btowc