summaryrefslogtreecommitdiff
path: root/xs_mime.h
diff options
context:
space:
mode:
authorGravatar default2024-04-14 19:26:49 +0200
committerGravatar default2024-04-14 19:26:49 +0200
commit0275658a3602f74035ff776dac8d8f64b9a2794f (patch)
treed9489684e46d7cd0d5bd8347a880316abe22f48f /xs_mime.h
parentBetter redirection URL building in oauth_post_handler(). (diff)
downloadsnac2-0275658a3602f74035ff776dac8d8f64b9a2794f.tar.gz
snac2-0275658a3602f74035ff776dac8d8f64b9a2794f.tar.xz
snac2-0275658a3602f74035ff776dac8d8f64b9a2794f.zip
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)
55 const char *ext = strrchr(file, '.'); 55 const char *ext = strrchr(file, '.');
56 56
57 if (ext) { 57 if (ext) {
58 const char **p = xs_mime_types; 58 xs *uext = xs_tolower_i(xs_dup(ext + 1));
59 xs *uext = xs_tolower_i(xs_dup(ext + 1)); 59 int b = 0;
60 int t = xs_countof(xs_mime_types) / 2 - 2;
60 61
61 while (*p) { 62 while (t >= b) {
62 int c; 63 int n = (b + t) / 2;
64 const char *p = xs_mime_types[n * 2];
63 65
64 if ((c = strcmp(*p, uext)) == 0) 66 int c = strcmp(uext, p);
65 return p[1]; 67
68 if (c < 0)
69 t = n - 1;
66 else 70 else
67 if (c > 0) 71 if (c > 0)
68 break; 72 b = n + 1;
69 73 else
70 p += 2; 74 return xs_mime_types[(n * 2) + 1];
71 } 75 }
72 } 76 }
73 77