Return a constant string from the mimes database.

We are not modifying it so there is no need to copy memory around.
This also prevents file_mime getting out of sync as had already
happend. It had a size of 50 while the mime types database type used
to have a size of 70.
This commit is contained in:
Florian Obser 2020-12-05 16:58:26 +01:00 committed by Solene Rapenne
commit bfd1f66350
3 changed files with 17 additions and 18 deletions

16
main.c
View file

@ -97,13 +97,13 @@ status(const int code, const char *file_mime, const char *lang)
void
display_file(const char *path, const char *lang)
{
size_t buflen = BUFF_LEN_1;
char *buffer[BUFF_LEN_1];
char extension[10];
char file_mime[50] = "";
ssize_t nread;
struct stat sb;
FILE *fd;
FILE *fd;
struct stat sb;
ssize_t nread;
size_t buflen = BUFF_LEN_1;
char *buffer[BUFF_LEN_1];
char extension[10];
const char *file_mime;
/* this is to check if path is a directory */
if (stat(path, &sb) == -1)
@ -117,7 +117,7 @@ display_file(const char *path, const char *lang)
if (S_ISDIR(sb.st_mode) == 1)
goto err;
get_file_mime(path, file_mime, sizeof(file_mime));
file_mime = get_file_mime(path);
status(20, file_mime, lang);