commit f862118b2d185e2a51500b2800d68ab1fed859fc
parent 036f6fa8f2a63cf54d0531913ab3da8a296e798c
Author: Francesco Saccone <francesco@francescosaccone.com>
Date: Tue, 1 Apr 2025 11:35:49 +0200
feat: add get_mime_type_from_extension function
Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>
Diffstat:
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/file.c b/file.c
@@ -5,6 +5,22 @@
#include <string.h>
#include <unistd.h>
+char *
+get_mime_type_from_extension(char *extension) {
+ char *default_type = "application/octet-stream";
+ size_t i,
+ number_of_types = sizeof(mime_types)
+ / sizeof(mime_types[0]);
+
+ for (i = 0; i < number_of_types; i++) {
+ if (strcmp(mime_types[i].extension, extension) == 0) {
+ return mime_types[i].type;
+ }
+ }
+
+ return default_type;
+}
+
int
is_file_readable(char *path) {
return (access(path, R_OK) == 0);
diff --git a/file.h b/file.h
@@ -33,6 +33,9 @@ struct file_content {
size_t length;
};
+char *
+get_mime_type_from_extension(char *extension);
+
int
is_file_readable(char *path);