bpaul-http

http server that will eventually be used for bpaul.xyz
Log | Files | Refs | README

commit 84779e82ee102cbd9de52dbccda021738a20f44d
parent 6f1cd0fc5e1fcbd85ce24b391319be9d5a0dc7ad
Author: benjamin paul <bpaul@bpaul.xyz>
Date:   Sun,  1 Aug 2021 21:14:43 +1000

oops i forgot to close the file

Diffstat:
Mfile.c | 15++++++++-------
Mmain.c | 1-
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/file.c b/file.c @@ -1,16 +1,15 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> +#include <sys/stat.h> size_t -fsize(FILE *f) { - size_t length; +fsize(const char *name) { + struct stat st; - fseek(f, 0, SEEK_END); - length = ftell(f); - fseek(f, 0, SEEK_SET); + stat(name, &st); - return length; + return st.st_size; } char * @@ -19,11 +18,13 @@ read_file(const char *name) { size_t length; FILE *f = fopen(name, "r"); - length = fsize(f); + length = fsize(name); buf = calloc(length+1, 1); fread(buf, 1, length, f); + fclose(f); + return buf; } diff --git a/main.c b/main.c @@ -35,7 +35,6 @@ main() { free(request); free(buf); - free(file_name); free(text); } }