summary refs log tree commit diff
path: root/port/wcwidth/wcswidth.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-25 13:01:33 -0400
committerJune McEnroe <june@causal.agency>2020-04-25 13:01:33 -0400
commit9de0ae65101269afdf8ea44775e6d2f2cef887b4 (patch)
treec48e459860da85b325f3807a5ab51c264787a15c /port/wcwidth/wcswidth.c
parentAdd Markus Kuhn's wcwidth implementation (diff)
downloadsrc-9de0ae65101269afdf8ea44775e6d2f2cef887b4.tar.gz
src-9de0ae65101269afdf8ea44775e6d2f2cef887b4.zip
Replace wcwidth implementation with that of musl
Imported from musl 1.2.0 sources.
Diffstat (limited to 'port/wcwidth/wcswidth.c')
-rw-r--r--port/wcwidth/wcswidth.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/port/wcwidth/wcswidth.c b/port/wcwidth/wcswidth.c
new file mode 100644
index 00000000..5c8a5a4d
--- /dev/null
+++ b/port/wcwidth/wcswidth.c
@@ -0,0 +1,8 @@
+#include <wchar.h>
+
+int wcswidth(const wchar_t *wcs, size_t n)
+{
+	int l=0, k=0;
+	for (; n-- && *wcs && (k = wcwidth(*wcs)) >= 0; l+=k, wcs++);
+	return (k < 0) ? k : l;
+}