summaryrefslogtreecommitdiff
path: root/www/libxpg4-ns/files/patch-aa
blob: df01df2795d6d7d2ddbf359f226de30832c6c50b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--- locale/ansi.c.orig	Sun Oct 25 14:06:42 1998
+++ locale/ansi.c	Sun Feb 28 00:59:25 1999
@@ -42,6 +42,7 @@
 #include <limits.h>
 #include <stddef.h>
 #include <rune.h>
+#include <string.h>
 
 int
 mblen(s, n)
@@ -105,9 +106,19 @@
 	char const *e;
 	int cnt = 0;
 
-	if (!pwcs || !s)
+	if (!s)
 		return (-1);
 
+	if (!pwcs) {
+		while (*s) {
+			if (sgetrune(s, MB_LEN_MAX, &e) == _INVALID_RUNE)
+				return (-1);
+			s = e;
+			++cnt;
+		}
+		return (cnt);
+	}
+
 	while (n-- > 0) {
 		*pwcs = sgetrune(s, MB_LEN_MAX, &e);
 		if (*pwcs == _INVALID_RUNE)
@@ -132,6 +143,13 @@
 	if (!pwcs || !s || n > INT_MAX)
 		return (-1);
 
+if( (pwcs[0]&0xffff0000) || ((!(pwcs[0]&0x8000))&&(pwcs[0]&0xff00)) ){
+  int len;
+  strncpy(s, (char *)pwcs, n);
+  len = strlen((char *)pwcs);
+  return (len < n) ? len : n;
+}
+
 	nb = n;
 	cnt = 0;
 	while (nb > 0) {
@@ -141,8 +159,10 @@
 		}
 		if (!sputrune(*pwcs++, s, nb, &e))
 			return (-1);		/* encoding error */
-		if (!e)			/* too long */
+		if (!e) {			/* too long */
+			*s = 0;
 			return (cnt);
+		}
 		cnt += e - s;
 		nb -= e - s;
 		s = e;