X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/e35fb433456859d250d2e075350d11d4e173713b..94187a80bd60baab4b9c4b949ad820d730578123:/sbr/mime_type.c diff --git a/sbr/mime_type.c b/sbr/mime_type.c index a640110a..cc6b1fbf 100644 --- a/sbr/mime_type.c +++ b/sbr/mime_type.c @@ -33,17 +33,13 @@ mime_type(const char *file_name) { /* Try to append charset for text content. */ char *mimeencoding; - if (strncasecmp(mimetype, "text", 4) == 0) { - if ((mimeencoding = get_file_info(MIMEENCODINGPROC, file_name))) { - content_type = concat(mimetype, "; charset=", mimeencoding, - NULL); - free (mimetype); - } else { - content_type = mimetype; - } - } else { + if (!strncasecmp(mimetype, "text", 4) && + (mimeencoding = get_file_info(MIMEENCODINGPROC, file_name))) { + content_type = concat(mimetype, "; charset=", mimeencoding, NULL); + free(mimeencoding); + free(mimetype); + } else content_type = mimetype; - } #else /* MIMEENCODINGPROC */ content_type = mimetype; #endif /* MIMEENCODINGPROC */ @@ -112,7 +108,7 @@ mime_type(const char *file_name) { #ifdef MIMETYPEPROC /* * Get information using proc about a file. - */ + * Non-null return value must be free(3)'d. */ static char * get_file_info(const char *proc, const char *file_name) { @@ -152,7 +148,7 @@ get_file_info(const char *proc, const char *file_name) if (!ok) return NULL; - /* s#^.*:[ \t]*##. */ + /* s#^[^:]*:[ \t]*##. */ info = buf; if ((needle = strchr(info, ':'))) { info = needle + 1;