path: root/cache.h
diff options
authorLinus Torvalds <>2005-10-13 18:03:18 (GMT)
committerJunio C Hamano <>2005-10-15 00:17:27 (GMT)
commit4546738b58a0134eef154231b07d60fc174d56e3 (patch)
tree873d8e5652c06c3891278f33546c437efc209c2d /cache.h
parentd402d5566fdf226697a386dfb9858e5d954e9b91 (diff)
Unlocalized isspace and friends
Do our own ctype.h, just to get the sane semantics: we want locale-independence, _and_ we want the right signed behaviour. Plus we only use a very small subset of ctype.h anyway (isspace, isalpha, isdigit and isalnum). Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'cache.h')
1 files changed, 26 insertions, 0 deletions
diff --git a/cache.h b/cache.h
index 3286582..f1d15ab 100644
--- a/cache.h
+++ b/cache.h
@@ -387,4 +387,30 @@ extern int git_config_bool(const char *, const char *);
extern char git_default_email[MAX_GITNAME];
extern char git_default_name[MAX_GITNAME];
+/* Sane ctype - no locale, and works with signed chars */
+#undef isspace
+#undef isdigit
+#undef isalpha
+#undef isalnum
+#undef tolower
+#undef toupper
+extern unsigned char sane_ctype[256];
+#define GIT_SPACE 0x01
+#define GIT_DIGIT 0x02
+#define GIT_ALPHA 0x04
+#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
+#define isspace(x) sane_istest(x,GIT_SPACE)
+#define isdigit(x) sane_istest(x,GIT_DIGIT)
+#define isalpha(x) sane_istest(x,GIT_ALPHA)
+#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
+#define tolower(x) sane_case((unsigned char)(x), 0x20)
+#define toupper(x) sane_case((unsigned char)(x), 0)
+static inline int sane_case(int x, int high)
+ if (sane_istest(x, GIT_ALPHA))
+ x = (x & ~0x20) | high;
+ return x;
#endif /* CACHE_H */