shithub: scc

Download patch

ref: c30ed6428967a83580b73c7c51efb47b24d7c876
parent: f4347d0c4b3eed5f0a65917453cfddd9dca1cb7a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Sep 16 02:56:04 EDT 2018

[lib/c] Support only charset between 0-127

--- a/lib/c/strcspn.c
+++ b/lib/c/strcspn.c
@@ -4,7 +4,7 @@
 size_t
 strcspn(const char *s1, const char *s2)
 {
-	char buf[256];
+	char buf[128];
 	unsigned char ch;
 	size_t n;
 
--- a/lib/c/strpbrk.c
+++ b/lib/c/strpbrk.c
@@ -4,14 +4,15 @@
 char *
 strpbrk(const char *s1, const char *s2)
 {
-	int c;
-	const char *p;
+	char buf[128];
+	unsigned ch;
 
-	for (; c = *s1; ++s1) {
-		for (p = s2; *p && *p != c; ++p)
-			;
-		if (*p == c)
-			return (char *) s1;
-	}
-	return NULL;
+	memset(buf, 0, sizeof(buf));
+	while (ch = *s2++)
+		buf[ch] = 1;
+
+	while ((ch = *s1) && !buf[ch])
+		s1++;
+
+	return (ch == '\0') ? NULL : (char *) s1;
 }
--- a/lib/c/strspn.c
+++ b/lib/c/strspn.c
@@ -4,7 +4,7 @@
 size_t
 strspn(const char *s1, const char *s2)
 {
-	char buf[256];
+	char buf[128];
 	unsigned char ch;
 	size_t n;