summaryrefslogtreecommitdiff
path: root/xs_mime.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-04-14 19:26:49 +0200
committerdefault <nobody@localhost>2024-04-14 19:26:49 +0200
commit0275658a3602f74035ff776dac8d8f64b9a2794f (patch)
treed9489684e46d7cd0d5bd8347a880316abe22f48f /xs_mime.h
parent81cf1e21a646568323681df2763e66f933bee48f (diff)
Backport from xs.
Diffstat (limited to 'xs_mime.h')
-rw-r--r--xs_mime.h22
1 files changed, 13 insertions, 9 deletions
diff --git a/xs_mime.h b/xs_mime.h
index 84af49c..853b092 100644
--- a/xs_mime.h
+++ b/xs_mime.h
@@ -55,19 +55,23 @@ const char *xs_mime_by_ext(const char *file)
const char *ext = strrchr(file, '.');
if (ext) {
- const char **p = xs_mime_types;
- xs *uext = xs_tolower_i(xs_dup(ext + 1));
+ xs *uext = xs_tolower_i(xs_dup(ext + 1));
+ int b = 0;
+ int t = xs_countof(xs_mime_types) / 2 - 2;
- while (*p) {
- int c;
+ while (t >= b) {
+ int n = (b + t) / 2;
+ const char *p = xs_mime_types[n * 2];
- if ((c = strcmp(*p, uext)) == 0)
- return p[1];
+ int c = strcmp(uext, p);
+
+ if (c < 0)
+ t = n - 1;
else
if (c > 0)
- break;
-
- p += 2;
+ b = n + 1;
+ else
+ return xs_mime_types[(n * 2) + 1];
}
}