summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2009-10-23 13:57:24 +0200
committerDenys Vlasenko2009-10-23 13:57:24 +0200
commit11c12c47201ee47a4d15044699915f23722e71d3 (patch)
tree683336e7c017a5e80cd546c643c94dd6f286a8e8
parenta7a1fd02cba88b47bc0faddd9ca301d58ff539cf (diff)
downloadbusybox-11c12c47201ee47a4d15044699915f23722e71d3.zip
busybox-11c12c47201ee47a4d15044699915f23722e71d3.tar.gz
fix isalnum and isxdigit. Unfortunately, +285 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h24
1 files changed, 22 insertions, 2 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 5d7426a..33fdca4 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1601,8 +1601,28 @@ extern const char bb_default_login_shell[];
* "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13.
*/
#define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); })
-#define isalnum(a) ({ unsigned char bb__isalnum = ((a)|0x20) - '0'; bb__isalnum <= 9 || (bb__isalnum - ('a' - '0')) <= 25; })
-#define isxdigit(a) ({ unsigned char bb__isxdigit = ((a)|0x20) - '0'; bb__isxdigit <= 9 || (bb__isxdigit - ('a' - '0')) <= 5; })
+
+// Bigger code:
+//#define isalnum(a) ({ unsigned char bb__isalnum = (a) - '0'; bb__isalnum <= 9 || ((bb__isalnum - ('A' - '0')) & 0xdf) <= 25; }) */
+#define isalnum(a) bb_ascii_isalnum(a)
+static ALWAYS_INLINE int bb_ascii_isalnum(unsigned char a)
+{
+ unsigned char b = a - '0';
+ if (b <= 9)
+ return (b <= 9);
+ b = (a|0x20) - 'a';
+ return b <= 'z' - 'a';
+}
+#define isxdigit(a) bb_ascii_isxdigit(a)
+static ALWAYS_INLINE int bb_ascii_isxdigit(unsigned char a)
+{
+ unsigned char b = a - '0';
+ if (b <= 9)
+ return (b <= 9);
+ b = (a|0x20) - 'a';
+ return b <= 'f' - 'a';
+}
+
// Unsafe wrt NUL!
//#define ispunct(a) (strchr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a)) != NULL)
#define ispunct(a) (strchrnul("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a))[0])