shithub: scc

Download patch

ref: b91d539b8c273c086f7b3548700c429d2ad7c5d4
parent: 1652b5cdb44fafba4c8343b993b0c5fd54923e16
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Sep 25 06:47:12 EDT 2017

[libc] Add macro definitions for tolower() and toupper()

The library is not thread safe in a lot of different places, and it
doesn't try to be thread safe because it will require a more complex
design, out of the scope of this simple library. For this reason
it is not a problem to use a global static variable.

--- a/lib/c/include/ctype.h
+++ b/lib/c/include/ctype.h
@@ -28,6 +28,7 @@
 #define _SP	0x80	/* hard space (0x20) */
 
 extern unsigned char __ctype[];
+extern int __ctmp;
 
 #define isalnum(c)  ((__ctype+1)[(c)] & (_U|_L|_D))
 #define isalpha(c)  ((__ctype+1)[(c)] & (_U|_L))
@@ -40,6 +41,9 @@
 #define isspace(c)  ((__ctype+1)[(c)] & (_S))
 #define isupper(c)  ((__ctype+1)[(c)] & (_U))
 #define isxdigit(c) ((__ctype+1)[(c)] & (_D|_X))
+
+#define tolower(c) ((__ctmp=c, isupper(__ctmp) ? __ctmp | 0x20 : __ctmp))
+#define toupper(c) ((__ctmp=c, islower(__ctmp) ? __ctmp & ~0x20 : __ctmp))
 
 #define isascii(c) ((unsigned)(c)<=0x7f)
 
--- a/lib/c/src/ctype.c
+++ b/lib/c/src/ctype.c
@@ -2,6 +2,8 @@
 #include <ctype.h>
 #undef ctype
 
+int __ctmp;
+
 /* __ctype is shifted by one to match EOF */
 unsigned char __ctype[257] = {
 	0,                                              /* EOF */