From 800ba738dc72f4c642bac20ec377590923bd9b63 Mon Sep 17 00:00:00 2001 From: Win Date: Wed, 5 Jun 2024 15:41:02 +0700 Subject: [PATCH] makefile --- Makefile | 15 ++++++++++++--- src/file.c | 2 +- src/file.h | 2 ++ src/server.c | 5 ++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 4dd66ec..b1c0f2a 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,19 @@ CFLAGS = -g -Wall TARGET = server -all: $(TARGET) +.PATH: ${.CURDIR}/src +.OBJPATH: ${.CURDIR}/obj -$(TARGET): src/$(TARGET).c - $(CC) $(CFLAGS) -o $(TARGET) src/$(TARGET).c +all: server + +server: server.o file.o + $(CC) $(CFLAGS) -o server server.o file.o + +server.o: server.c server.h + $(CC) $(CFLAGS) -c server.c + +file.o: file.c file.h + $(CC) $(CFLAGS) -c clean: $(RM) $(TARGET) diff --git a/src/file.c b/src/file.c index df167e6..fd1d1cf 100644 --- a/src/file.c +++ b/src/file.c @@ -13,7 +13,7 @@ void get_file_path(char *uri, char *file_path) { strncat(uri, "index.html", 11); } - strncpy(file_path, "htdocs", 7); + strncpy(file_path, file_dir, (int)sizeof(file_dir)); printf("%s\n", file_path); strncat(file_path, uri, (int)sizeof(uri)); diff --git a/src/file.h b/src/file.h index bc67e5a..9621f9e 100644 --- a/src/file.h +++ b/src/file.h @@ -2,3 +2,5 @@ void get_file_path(char *uri, char *file_path); void get_mime_type(char *file, char *mime); + +static const char file_dir[] = "htdocs"; diff --git a/src/server.c b/src/server.c index 08f643e..5cb2e0f 100644 --- a/src/server.c +++ b/src/server.c @@ -121,8 +121,11 @@ int main() { fseek(file, 0, SEEK_SET); printf("Size of File: %ld\n", file_size); + + char mime_type[15]; + get_mime_type(uri, mime_type); - send_response(client_sock_fd, OK_HEAD, "text/html", file, file_size); + send_response(client_sock_fd, OK_HEAD, mime_type, file, file_size); fclose(file); }