summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/wcswidth.c
diff options
context:
space:
mode:
authorstsp <>2011-04-04 18:16:24 +0000
committerstsp <>2011-04-04 18:16:24 +0000
commit515602fafdedd66b15c0d7c6a1902217acea3b8e (patch)
tree59229a77bf938176eb0293b60ecb093b44e0e6d5 /src/lib/libc/string/wcswidth.c
parentb34795695975df97bc9658c650b8fb5bb3d56912 (diff)
downloadopenbsd-515602fafdedd66b15c0d7c6a1902217acea3b8e.tar.gz
openbsd-515602fafdedd66b15c0d7c6a1902217acea3b8e.tar.bz2
openbsd-515602fafdedd66b15c0d7c6a1902217acea3b8e.zip
Add a wcswidth man page (based on FreeBSD), and fix the implementation
to return -1 in case of an unprintable character. ok nicm jmc
Diffstat (limited to 'src/lib/libc/string/wcswidth.c')
-rw-r--r--src/lib/libc/string/wcswidth.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lib/libc/string/wcswidth.c b/src/lib/libc/string/wcswidth.c
index cd240897b5..8ea1bdf6e6 100644
--- a/src/lib/libc/string/wcswidth.c
+++ b/src/lib/libc/string/wcswidth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: wcswidth.c,v 1.3 2005/08/08 08:05:37 espie Exp $ */ 1/* $OpenBSD: wcswidth.c,v 1.4 2011/04/04 18:16:24 stsp Exp $ */
2/* $NetBSD: wcswidth.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ 2/* $NetBSD: wcswidth.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */
3 3
4/*- 4/*-
@@ -34,11 +34,14 @@
34int 34int
35wcswidth(const wchar_t *s, size_t n) 35wcswidth(const wchar_t *s, size_t n)
36{ 36{
37 int w; 37 int w, q;
38 38
39 w = 0; 39 w = 0;
40 while (n && *s) { 40 while (n && *s) {
41 w += wcwidth(*s); 41 q = wcwidth(*s);
42 if (q == -1)
43 return (-1);
44 w += q;
42 s++; 45 s++;
43 n--; 46 n--;
44 } 47 }