scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit c4b7399c26bf3040f33b4760e162495d74d85d73
parent 534e0b91e27ad3cb37404d696cd1c0044a8ebe18
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Sun,  4 Jan 2026 20:17:51 +0100

libc/wchar: Add btowc()

Diffstat:
Msrc/libc/objs/common-objs.mk | 1+
Msrc/libc/wchar/Makefile | 1+
Asrc/libc/wchar/btowc.c | 14++++++++++++++
Mtests/libc/execute/.gitignore | 1+
Atests/libc/execute/0065-btowc.c | 22++++++++++++++++++++++
Mtests/libc/execute/libc-tests.lst | 1+
6 files changed, 40 insertions(+), 0 deletions(-)

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\ 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\ 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; +} diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore @@ -63,3 +63,4 @@ 0063-wcspbrk 0064-wcstok test.log +0065-btowc 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; +} 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