1
0
mirror of https://github.com/fumiama/simple-http-server.git synced 2026-06-10 04:50:24 +08:00

Update server.c

This commit is contained in:
源文雨
2021-06-07 22:05:06 +08:00
committed by GitHub
parent c11330eedd
commit c85e9c51e0

View File

@@ -111,8 +111,7 @@ void accept_request(void *cli) {
numchars = get_line(client, buf, sizeof(buf)); numchars = get_line(client, buf, sizeof(buf));
not_found(client); not_found(client);
} }
else else {
{
if ((st.st_mode & S_IFMT) == S_IFDIR) { if ((st.st_mode & S_IFMT) == S_IFDIR) {
//getcwd(path, sizeof(path)); //getcwd(path, sizeof(path));
strcat(path, "/index.html"); strcat(path, "/index.html");
@@ -157,11 +156,11 @@ void bad_request(int client) {
* FILE pointer for the file to cat */ * FILE pointer for the file to cat */
/**********************************************************************/ /**********************************************************************/
void cat(int client, FILE *resource) { void cat(int client, FILE *resource) {
fseek(resource, 0, SEEK_END);
off_t len = 0; off_t len = 0;
#if __APPLE__ #if __APPLE__
sendfile(fileno(resource), client, 0, &len, &hdtr, 0); sendfile(fileno(resource), client, 0, &len, &hdtr, 0);
#else #else
fseek(resource, 0, SEEK_END);
off_t file_size = ftell(resource); off_t file_size = ftell(resource);
rewind(resource); rewind(resource);
sendfile(client, fileno(resource), &len, file_size); sendfile(client, fileno(resource), &len, file_size);