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
commita8b4624387f580759739aa064e3f489bf28afeae (patch)
tree084e13a3e46da74a96965dcee5fab9c6c9f500f7 /port/wcwidth/wcswidth.c
parentAdd Markus Kuhn's wcwidth implementation (diff)
downloadsrc-a8b4624387f580759739aa064e3f489bf28afeae.tar.gz
src-a8b4624387f580759739aa064e3f489bf28afeae.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;
+}