From 5a238e86664880256f99eb98b0ad301160cf50b0 Mon Sep 17 00:00:00 2001 From: Florian Obser Date: Sun, 6 Dec 2020 11:27:43 +0100 Subject: [PATCH] Use BUFSIZ for the amount of data to copy through stdio. According to the book of armaments(posix): BUFSIZ Size of buffers. This shall expand to a positive value. There is also no need for the buflen variable since the size never changes during runtime and the compiler can infer the size via sizeof(). --- main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index d68d0f8..a931773 100644 --- a/main.c +++ b/main.c @@ -12,7 +12,6 @@ #include "mimes.h" -#define BUFF_LEN_1 1000 #define BUFF_LEN_2 1025 #define BUFF_LEN_3 1024 #define GEMINI_PART 9 @@ -100,8 +99,7 @@ display_file(const char *path, const char *lang) FILE *fd; struct stat sb; ssize_t nread; - size_t buflen = BUFF_LEN_1; - char *buffer[BUFF_LEN_1]; + char *buffer[BUFSIZ]; char extension[10]; const char *file_mime; @@ -122,7 +120,7 @@ display_file(const char *path, const char *lang) status(20, file_mime, lang); /* read the file and write it to stdout */ - while ((nread = fread(buffer, sizeof(char), buflen, fd)) != 0) + while ((nread = fread(buffer, sizeof(char), sizeof(buffer), fd)) != 0) fwrite(buffer, sizeof(char), nread, stdout); fclose(fd); syslog(LOG_DAEMON, "path served %s", path);