shithub: scc

Download patch

ref: 563f6cff7bec0a6c084721d6a46bdd0e88d6d78c
parent: 45871c6d68969b6052e4cd983084f7b5c44b4be0
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Mar 8 10:16:26 EST 2017

[libc] Don't use _ctype symbol

The tradicional implementation of ctype uses the symbol _ctype,
(for example V7 or plan9 implementations), but _ctype is a
name that can be used by local variables, and they can hide the
symbol used by ctype.h. The best solution is to use the __
namespace, which cannot be used in any case.

--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -28,19 +28,19 @@
 #define _X	0x40	/* hex char */
 #define _SP	0x80	/* hard space (0x20) */
 
-extern unsigned char _ctype[];
+extern unsigned char __ctype[];
 
-#define isalnum(c)  (_ctype[(unsigned char) c] & (_U|_L|_D))
-#define isalpha(c)  (_ctype[(unsigned char) c] & (_U|_L))
-#define iscntrl(c)  (_ctype[(unsigned char) c] & (_C))
-#define isdigit(c)  (_ctype[(unsigned char) c] & (_D))
-#define isgraph(c)  (_ctype[(unsigned char) c] & (_P|_U|_L|_D))
-#define islower(c)  (_ctype[(unsigned char) c] & (_L))
-#define isprint(c)  (_ctype[(unsigned char) c] & (_P|_U|_L|_D|_SP))
-#define ispunct(c)  (_ctype[(unsigned char) c] & (_P))
-#define isspace(c)  (_ctype[(unsigned char) c] & (_S))
-#define isupper(c)  (_ctype[(unsigned char) c] & (_U))
-#define isxdigit(c) (_ctype[(unsigned char) c] & (_D|_X))
+#define isalnum(c)  (__ctype[(unsigned char) c] & (_U|_L|_D))
+#define isalpha(c)  (__ctype[(unsigned char) c] & (_U|_L))
+#define iscntrl(c)  (__ctype[(unsigned char) c] & (_C))
+#define isdigit(c)  (__ctype[(unsigned char) c] & (_D))
+#define isgraph(c)  (__ctype[(unsigned char) c] & (_P|_U|_L|_D))
+#define islower(c)  (__ctype[(unsigned char) c] & (_L))
+#define isprint(c)  (__ctype[(unsigned char) c] & (_P|_U|_L|_D|_SP))
+#define ispunct(c)  (__ctype[(unsigned char) c] & (_P))
+#define isspace(c)  (__ctype[(unsigned char) c] & (_S))
+#define isupper(c)  (__ctype[(unsigned char) c] & (_U))
+#define isxdigit(c) (__ctype[(unsigned char) c] & (_D|_X))
 
 #define isascii(c) (((unsigned) c)<=0x7f)
 
--- a/libc/src/ctype.c
+++ b/libc/src/ctype.c
@@ -4,7 +4,7 @@
 #include <ctype.h>
 #undef ctype
 
-unsigned char _ctype[255] = {
+unsigned char __ctype[255] = {
 	_C,_C,_C,_C,_C,_C,_C,_C,                        /* 0-7 */
 	_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C,         /* 8-15 */
 	_C,_C,_C,_C,_C,_C,_C,_C,                        /* 16-23 */
--- a/libc/src/isalnum.c
+++ b/libc/src/isalnum.c
@@ -7,5 +7,5 @@
 int
 isalnum(int c)
 {
-	return _ctype[(unsigned char) c] & (_U|_L|_D);
+	return __ctype[(unsigned char) c] & (_U|_L|_D);
 }
--- a/libc/src/isalpha.c
+++ b/libc/src/isalpha.c
@@ -7,5 +7,5 @@
 int
 isalpha(int c)
 {
-	return _ctype[(unsigned char) c] & (_U|_L);
+	return __ctype[(unsigned char) c] & (_U|_L);
 }
--- a/libc/src/iscntrl.c
+++ b/libc/src/iscntrl.c
@@ -7,5 +7,5 @@
 int
 iscntrl(int c)
 {
-	return _ctype[(unsigned char) c] & (_C);
+	return __ctype[(unsigned char) c] & (_C);
 }
--- a/libc/src/isdigit.c
+++ b/libc/src/isdigit.c
@@ -7,5 +7,5 @@
 int
 isdigit(int c)
 {
-	return _ctype[(unsigned char) c] & (_D);
+	return __ctype[(unsigned char) c] & (_D);
 }
--- a/libc/src/isgraph.c
+++ b/libc/src/isgraph.c
@@ -7,5 +7,5 @@
 int
 isgraph(int c)
 {
-	return _ctype[(unsigned char) c] & (_P|_U|_L|_D);
+	return __ctype[(unsigned char) c] & (_P|_U|_L|_D);
 }
--- a/libc/src/islower.c
+++ b/libc/src/islower.c
@@ -7,5 +7,5 @@
 int
 islower(int c)
 {
-	return _ctype[(unsigned char) c] & _L;
+	return __ctype[(unsigned char) c] & _L;
 }
--- a/libc/src/isprint.c
+++ b/libc/src/isprint.c
@@ -7,5 +7,5 @@
 int
 isprint(int c)
 {
-	return _ctype[(unsigned char) c] & (_P|_U|_L|_D|_SP);
+	return __ctype[(unsigned char) c] & (_P|_U|_L|_D|_SP);
 }
--- a/libc/src/ispunct.c
+++ b/libc/src/ispunct.c
@@ -7,5 +7,5 @@
 int
 ispunct(int c)
 {
-	return _ctype[(unsigned char) c] & (_P);
+	return __ctype[(unsigned char) c] & (_P);
 }
--- a/libc/src/isspace.c
+++ b/libc/src/isspace.c
@@ -7,5 +7,5 @@
 int
 isspace(int c)
 {
-	return _ctype[(unsigned char) c] & _S;
+	return __ctype[(unsigned char) c] & _S;
 }
--- a/libc/src/isupper.c
+++ b/libc/src/isupper.c
@@ -7,5 +7,5 @@
 int
 isupper(int c)
 {
-	return _ctype[(unsigned char) c] & _U;
+	return __ctype[(unsigned char) c] & _U;
 }
--- a/libc/src/isxdigit.c
+++ b/libc/src/isxdigit.c
@@ -7,5 +7,5 @@
 int
 isxdigit(int c)
 {
-	return _ctype[(unsigned char) c] & (_D|_X);
+	return __ctype[(unsigned char) c] & (_D|_X);
 }