diff options
author | Omar Polo <op@omarpolo.com> | 2022-09-10 09:40:05 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2022-09-10 09:40:05 +0000 |
commit | aa9543b9fd1963d86f63fda13addb356f9039c37 (patch) | |
tree | e01438402f1c2dfd9aa5d34a54701681fcf62c68 /mime.c | |
parent | 7277bb7dc2971fad2a51b7975df85dda1df4c936 (diff) |
make the mime types fixed-sized too
Diffstat (limited to 'mime.c')
-rw-r--r-- | mime.c | 18 |
1 files changed, 3 insertions, 15 deletions
@@ -35,7 +35,6 @@ init_mime(struct mime *mime) int add_mime(struct mime *mime, const char *mt, const char *ext) { - char *mimetype, *extension; struct etm *t; size_t newcap; @@ -49,15 +48,11 @@ add_mime(struct mime *mime, const char *mt, const char *ext) mime->cap = newcap; } - if ((mimetype = strdup(mt)) == NULL) + t = &mime->t[mime->len]; + if (strlcpy(t->mime, mt, sizeof(t->mime)) >= sizeof(t->mime)) return -1; - if ((extension = strdup(ext)) == NULL) { - free(mimetype); + if (strlcpy(t->ext, ext, sizeof(t->ext)) >= sizeof(t->ext)) return -1; - } - - mime->t[mime->len].mime = mimetype; - mime->t[mime->len].ext = extension; mime->len++; return 0; } @@ -157,12 +152,5 @@ mime(struct vhost *host, const char *path) void free_mime(struct mime *m) { - struct etm *t; - - for (t = m->t; t->mime != NULL; ++t) { - free(t->mime); - free(t->ext); - } - free(m->t); } |