From c85e9c51e00f3620f407af3bbc6dae2a3f10b656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Mon, 7 Jun 2021 22:05:06 +0800 Subject: [PATCH] Update server.c --- server.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server.c b/server.c index 60a04ac..504bdd2 100644 --- a/server.c +++ b/server.c @@ -111,8 +111,7 @@ void accept_request(void *cli) { numchars = get_line(client, buf, sizeof(buf)); not_found(client); } - else - { + else { if ((st.st_mode & S_IFMT) == S_IFDIR) { //getcwd(path, sizeof(path)); strcat(path, "/index.html"); @@ -157,11 +156,11 @@ void bad_request(int client) { * FILE pointer for the file to cat */ /**********************************************************************/ void cat(int client, FILE *resource) { - fseek(resource, 0, SEEK_END); off_t len = 0; #if __APPLE__ sendfile(fileno(resource), client, 0, &len, &hdtr, 0); #else + fseek(resource, 0, SEEK_END); off_t file_size = ftell(resource); rewind(resource); sendfile(client, fileno(resource), &len, file_size);