ref: 6859d1792ba613abe045e4c51393493d328bd518
parent: 6d3d7af1e88c1e466579c95b6538d0f2c9bebd8a
author: Hiltjo Posthuma <[email protected]>
date: Tue Mar 15 12:20:15 EDT 2022
libc: wchar: initial wcwidth implementation (incomplete)
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -91,6 +91,5 @@
extern size_t wcrtomb(char * restrict s, wchar_t wc, mbstate_t * restrict ps);
extern size_t mbsrtowcs(wchar_t * restrict dst, const char ** restrict src, size_t len, mbstate_t * restrict ps);
extern size_t wcsrtombs(char * restrict dst, const wchar_t ** restrict src, size_t len, mbstate_t * restrict ps);
-
-
+extern int wcwidth(wchar_t wc);
#endif
--- a/src/libc/Makefile
+++ b/src/libc/Makefile
@@ -9,6 +9,7 @@
stdlib\
string\
time\
+ wchar\
arch\
include $(PROJECTDIR)/scripts/rules.mk
--- /dev/null
+++ b/src/libc/wchar/Makefile
@@ -1,0 +1,11 @@
+.POSIX:
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+include ../rules.mk
+
+OBJS =\
+ wcwidth.$O\
+
+all: $(OBJS)
+
+include deps.mk
--- /dev/null
+++ b/src/libc/wchar/deps.mk
@@ -1,0 +1,1 @@
+#deps
--- /dev/null
+++ b/src/libc/wchar/wcwidth.c
@@ -1,0 +1,13 @@
+#include <wchar.h>
+#undef wcwidth
+
+/* incomplete, needs a real implementation */
+int
+wcwidth(wchar_t wc)
+{
+ if (!wc)
+ return 0;
+ else if (wc < 32 || wc >= 127)
+ return -1;
+ return 1;
+}