bpaul-http

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

commit 18d0851e865fcae376afa9af99f3667291fd8146
parent 0007faaa1c4a3333a2410f621b96dddfbf5b3a42
Author: benjamin paul <bpaul@bpaul.xyz>
Date:   Sun,  1 Aug 2021 17:45:10 +1000

file size function

Diffstat:
Afile.c | 12++++++++++++
Afile.h | 5+++++
Mmain.c | 5++---
3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/file.c b/file.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +size_t +fsize(FILE *f) { + size_t length; + + fseek(f, 0, SEEK_END); + length = ftell(f); + fseek(f, 0, SEEK_SET); + + return length; +} diff --git a/file.h b/file.h @@ -0,0 +1,5 @@ +#pragma once + +#include <stdio.h> + +size_t fsize(FILE *f); diff --git a/main.c b/main.c @@ -1,3 +1,4 @@ +#include "file.h" #include "http.h" #include "tcp.h" #include <stdio.h> @@ -13,9 +14,7 @@ main() { char *buf; size_t length; FILE *f = fopen("index.html", "r"); - fseek(f, 0, SEEK_END); - length = ftell(f); - fseek(f, 0, SEEK_SET); + length = fsize(f); buf = malloc(length); fread(buf, 1, length, f);