From a05fdee0161cea1ed1beac59e2f4a9b7f65d0bd9 Mon Sep 17 00:00:00 2001 From: Solene Rapenne Date: Thu, 3 Dec 2020 23:03:08 +0100 Subject: [PATCH] Remove database iterator, no longer useful after the MIME database change. Proposed by oa. --- main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 45a241d..e2d37e3 100644 --- a/main.c +++ b/main.c @@ -32,15 +32,14 @@ status(const int code, const char *file_mime, const char *lang) void get_file_mime(const char *path, char *type, const ssize_t type_size) { - struct mimes *iterator = database; char *extension; extension = strrchr(path, '.'); /* look for the MIME in the database */ - for (int i = 0; i < sizeof(database) / sizeof(struct mimes); i++, iterator++) { - if (strcmp(iterator->extension, extension + 1) == 0) { - strlcpy(type, iterator->type, type_size); + for (int i = 0; i < sizeof(database) / sizeof(struct mimes); i++) { + if (strcmp(database[i].extension, extension + 1) == 0) { + strlcpy(type, database[i].type, type_size); break; } } @@ -79,6 +78,7 @@ display_file(const char *path, const char *lang) fwrite(buffer, sizeof(char), nread, stdout); fclose(fd); } else { + /* return an error code and no content */ status(40, "text/gemini", lang); } @@ -94,10 +94,10 @@ main(int argc, char **argv) char path [BUFF_LEN_2] = DEFAULT_CHROOT; char lang [3] = DEFAULT_LANG; char user [_SC_LOGIN_NAME_MAX]; - struct passwd *pw; int virtualhost = 0; int option; int start_with_gemini; + struct passwd *pw; char *pos; while ((option = getopt(argc, argv, ":d:l:u:v")) != -1) {