diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-01-20 21:33:56 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-01-20 21:33:56 +0000 |
commit | a87980c2eb8933e2d291e3a2dc009aa69e82e128 (patch) | |
tree | 1e936d62c9fb589981d1f35cc555e6f0c7b7dc2f /src/common/compat.h | |
parent | d20ae4962f24098eba179064d5c9f971ee85d0e6 (diff) | |
download | tor-a87980c2eb8933e2d291e3a2dc009aa69e82e128.tar.gz tor-a87980c2eb8933e2d291e3a2dc009aa69e82e128.zip |
Add a better (non-locale-having) ctypes implementation to avoid protocol and parsing mismatches on different platforms.
svn:r18189
Diffstat (limited to 'src/common/compat.h')
-rw-r--r-- | src/common/compat.h | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index d1a7b3d944..f077b88e05 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -31,9 +31,6 @@ #ifdef HAVE_STRING_H #include <string.h> #endif -#ifdef HAVE_CTYPE_H -#include <ctype.h> -#endif #ifdef HAVE_PTHREAD_H #include <pthread.h> #endif @@ -248,20 +245,27 @@ tor_memstr(const void *haystack, size_t hlen, const char *needle) return tor_memmem(haystack, hlen, needle, strlen(needle)); } -/* This cast-to-uchar, then-cast-to-int business is needed to compile and - * run properly on some Solarises. */ - -#define TOR_ISALPHA(c) isalpha((int)(unsigned char)(c)) -#define TOR_ISALNUM(c) isalnum((int)(unsigned char)(c)) -#define TOR_ISSPACE(c) isspace((int)(unsigned char)(c)) -#define TOR_ISXDIGIT(c) isxdigit((int)(unsigned char)(c)) -#define TOR_ISDIGIT(c) isdigit((int)(unsigned char)(c)) -#define TOR_ISPRINT(c) isprint((int)(unsigned char)(c)) -#define TOR_ISLOWER(c) islower((int)(unsigned char)(c)) -#define TOR_ISUPPER(c) isupper((int)(unsigned char)(c)) - -#define TOR_TOLOWER(c) ((char)tolower((int)(unsigned char)(c))) -#define TOR_TOUPPER(c) ((char)toupper((int)(unsigned char)(c))) +/* Much of the time when we're checking ctypes, we're doing spec compliance, + * which all assumes we're doing ASCII. */ +#define DECLARE_CTYPE_FN(name) \ + static int TOR_##name(char c); \ + extern const uint32_t const TOR_##name##_TABLE[]; \ + static INLINE int TOR_##name(char c) { \ + uint8_t u = c; \ + return !!(TOR_##name##_TABLE[(u >> 5) & 7] & (1 << (u & 31))); \ + } +DECLARE_CTYPE_FN(ISALPHA) +DECLARE_CTYPE_FN(ISALNUM) +DECLARE_CTYPE_FN(ISSPACE) +DECLARE_CTYPE_FN(ISDIGIT) +DECLARE_CTYPE_FN(ISXDIGIT) +DECLARE_CTYPE_FN(ISPRINT) +DECLARE_CTYPE_FN(ISLOWER) +DECLARE_CTYPE_FN(ISUPPER) +extern const char const TOR_TOUPPER_TABLE[]; +extern const char const TOR_TOLOWER_TABLE[]; +#define TOR_TOLOWER(c) (TOR_TOLOWER_TABLE[(uint8_t)c]) +#define TOR_TOUPPER(c) (TOR_TOUPPER_TABLE[(uint8_t)c]) #ifdef MS_WINDOWS #define _SHORT_FILE_ (tor_fix_source_file(__FILE__)) |