diff options
| author | 2024-04-14 19:26:49 +0200 | |
|---|---|---|
| committer | 2024-04-14 19:26:49 +0200 | |
| commit | 0275658a3602f74035ff776dac8d8f64b9a2794f (patch) | |
| tree | d9489684e46d7cd0d5bd8347a880316abe22f48f /xs_mime.h | |
| parent | Better redirection URL building in oauth_post_handler(). (diff) | |
| download | penes-snac2-0275658a3602f74035ff776dac8d8f64b9a2794f.tar.gz penes-snac2-0275658a3602f74035ff776dac8d8f64b9a2794f.tar.xz penes-snac2-0275658a3602f74035ff776dac8d8f64b9a2794f.zip | |
Backport from xs.
Diffstat (limited to '')
| -rw-r--r-- | xs_mime.h | 22 |
1 files changed, 13 insertions, 9 deletions
| @@ -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 | ||