git__tolower: a tolower() that isn't dumb Some brain damaged tolower() implementations appear to want to take the locale into account, and this may require taking some insanely aggressive lock on the locale and slowing down what should be the most trivial of trivial calls for people who just want to downcase ASCII.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
diff --git a/src/config_file.c b/src/config_file.c
index d6a62b8..52a5376 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -156,7 +156,7 @@ int git_config_file_normalize_section(char *start, char *end)
if (end && scan >= end)
break;
if (isalnum(*scan))
- *scan = (char)tolower(*scan);
+ *scan = (char)git__tolower(*scan);
else if (*scan != '-' || scan == start)
return GIT_EINVALIDSPEC;
}
@@ -1083,7 +1083,7 @@ static int parse_section_header(struct reader *reader, char **section_out)
goto fail_parse;
}
- name[name_length++] = (char) tolower(c);
+ name[name_length++] = (char)git__tolower(c);
} while ((c = line[pos++]) != ']');
diff --git a/src/fnmatch.c b/src/fnmatch.c
index d7899e3..a2945b8 100644
--- a/src/fnmatch.c
+++ b/src/fnmatch.c
@@ -164,8 +164,8 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
default:
normal:
if (c != *string && !((flags & FNM_CASEFOLD) &&
- (tolower((unsigned char)c) ==
- tolower((unsigned char)*string))))
+ (git__tolower((unsigned char)c) ==
+ git__tolower((unsigned char)*string))))
return (FNM_NOMATCH);
++string;
break;
@@ -190,7 +190,7 @@ rangematch(const char *pattern, char test, int flags, char **newp)
++pattern;
if (flags & FNM_CASEFOLD)
- test = (char)tolower((unsigned char)test);
+ test = (char)git__tolower((unsigned char)test);
/*
* A right bracket shall lose its special meaning and represent
@@ -207,7 +207,7 @@ rangematch(const char *pattern, char test, int flags, char **newp)
if (c == '/' && (flags & FNM_PATHNAME))
return (RANGE_NOMATCH);
if ((flags & FNM_CASEFOLD))
- c = (char)tolower((unsigned char)c);
+ c = (char)git__tolower((unsigned char)c);
if (*pattern == '-'
&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
pattern += 2;
@@ -216,7 +216,7 @@ rangematch(const char *pattern, char test, int flags, char **newp)
if (c2 == EOS)
return (RANGE_ERROR);
if (flags & FNM_CASEFOLD)
- c2 = (char)tolower((unsigned char)c2);
+ c2 = (char)git__tolower((unsigned char)c2);
if (c <= test && test <= c2)
ok = 1;
} else if (c == test)
diff --git a/src/iterator.c b/src/iterator.c
index c5c5fd7..52b4cd7 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -1401,10 +1401,10 @@ GIT_INLINE(bool) workdir_path_is_dotgit(const git_buf *path)
if (path->ptr[len - 1] == '/')
len--;
- if (tolower(path->ptr[len - 1]) != 't' ||
- tolower(path->ptr[len - 2]) != 'i' ||
- tolower(path->ptr[len - 3]) != 'g' ||
- tolower(path->ptr[len - 4]) != '.')
+ if (git__tolower(path->ptr[len - 1]) != 't' ||
+ git__tolower(path->ptr[len - 2]) != 'i' ||
+ git__tolower(path->ptr[len - 3]) != 'g' ||
+ git__tolower(path->ptr[len - 4]) != '.')
return false;
return (len == 4 || path->ptr[len - 5] == '/');
diff --git a/src/netops.c b/src/netops.c
index 6047cf1..5e80755 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -84,7 +84,7 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons)
int gitno__match_host(const char *pattern, const char *host)
{
for (;;) {
- char c = tolower(*pattern++);
+ char c = git__tolower(*pattern++);
if (c == '\0')
return *host ? -1 : 0;
@@ -102,7 +102,7 @@ int gitno__match_host(const char *pattern, const char *host)
*/
while(*host) {
- char h = tolower(*host);
+ char h = git__tolower(*host);
if (c == h)
return gitno__match_host(pattern, host++);
if (h == '.')
@@ -112,7 +112,7 @@ int gitno__match_host(const char *pattern, const char *host)
return -1;
}
- if (c != tolower(*host++))
+ if (c != git__tolower(*host++))
return -1;
}
diff --git a/src/path.c b/src/path.c
index 81b4d51..d791535 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1471,7 +1471,7 @@ static int32_t next_hfs_char(const char **in, size_t *len)
* the ASCII range, which is perfectly fine, because the
* git folder name can only be composed of ascii characters
*/
- return tolower(codepoint);
+ return git__tolower(codepoint);
}
return 0; /* NULL byte -- end of string */
}
diff --git a/src/util.c b/src/util.c
index b8d6cf5..c628264 100644
--- a/src/util.c
+++ b/src/util.c
@@ -171,9 +171,9 @@ int git__strcmp(const char *a, const char *b)
int git__strcasecmp(const char *a, const char *b)
{
- while (*a && *b && tolower(*a) == tolower(*b))
+ while (*a && *b && git__tolower(*a) == git__tolower(*b))
++a, ++b;
- return ((unsigned char)tolower(*a) - (unsigned char)tolower(*b));
+ return ((unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b));
}
int git__strcasesort_cmp(const char *a, const char *b)
@@ -182,7 +182,7 @@ int git__strcasesort_cmp(const char *a, const char *b)
while (*a && *b) {
if (*a != *b) {
- if (tolower(*a) != tolower(*b))
+ if (git__tolower(*a) != git__tolower(*b))
break;
/* use case in sort order even if not in equivalence */
if (!cmp)
@@ -193,7 +193,7 @@ int git__strcasesort_cmp(const char *a, const char *b)
}
if (*a || *b)
- return (unsigned char)tolower(*a) - (unsigned char)tolower(*b);
+ return (unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b);
return cmp;
}
@@ -212,8 +212,8 @@ int git__strncasecmp(const char *a, const char *b, size_t sz)
int al, bl;
do {
- al = (unsigned char)tolower(*a);
- bl = (unsigned char)tolower(*b);
+ al = (unsigned char)git__tolower(*a);
+ bl = (unsigned char)git__tolower(*b);
++a, ++b;
} while (--sz && al && al == bl);
@@ -225,7 +225,7 @@ void git__strntolower(char *str, size_t len)
size_t i;
for (i = 0; i < len; ++i) {
- str[i] = (char) tolower(str[i]);
+ str[i] = (char)git__tolower(str[i]);
}
}
@@ -255,8 +255,8 @@ int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix)
int s, p;
while(str_n--) {
- s = (unsigned char)tolower(*str++);
- p = (unsigned char)tolower(*prefix++);
+ s = (unsigned char)git__tolower(*str++);
+ p = (unsigned char)git__tolower(*prefix++);
if (s != p)
return s - p;
diff --git a/src/util.h b/src/util.h
index be65345..b2abbe6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -275,6 +275,15 @@ extern char *git__strsep(char **end, const char *sep);
extern void git__strntolower(char *str, size_t len);
extern void git__strtolower(char *str);
+#ifdef GIT_WIN32
+GIT_INLINE(int) git__tolower(int c)
+{
+ return (c >= 'A' && c <= 'Z') ? (c + 32) : c;
+}
+#else
+# define git__tolower(a) tolower(a)
+#endif
+
GIT_INLINE(const char *) git__next_line(const char *s)
{
while (*s && *s != '\n') s++;