Use BUFSIZ for the amount of data to copy through stdio.

According to the book of armaments(posix):
    Size of <stdio.h> 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
This commit is contained in:
Florian Obser 2020-12-06 11:27:43 +01:00 committed by Solene Rapenne
parent 8c5e344707
commit 5a238e8666

View file

@ -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);
syslog(LOG_DAEMON, "path served %s", path);