* is responsible for free'ing returned memory.
*/
char *
-mime_type(const char *file_name) {
+mime_type(const char *file_name)
+{
char *content_type = NULL; /* mime content type */
char *p;
- static int loaded_defaults = 0;
#ifdef MIMETYPEPROC
char *mimetype;
/* 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 */
struct node *np; /* Content scan node pointer */
FILE *fp; /* File pointer for mhn.defaults */
+ static bool loaded_defaults;
if (! loaded_defaults &&
(fp = fopen(p = etcpath("mhn.defaults"), "r"))) {
- loaded_defaults = 1;
+ loaded_defaults = true;
readconfig(NULL, fp, p, 0);
fclose(fp);
}
if (content_type == NULL) {
FILE *fp;
- int binary = 0, c;
+ int c;
if (!(fp = fopen(file_name, "r"))) {
inform("unable to access file \"%s\"", file_name);
return NULL;
}
+ bool binary = false;
while ((c = getc(fp)) != EOF) {
if (! isascii(c) || c == 0) {
- binary = 1;
+ binary = true;
break;
}
}
#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)
{
if (!ok)
return NULL;
- /* s#^.*:[ \t]*##. */
+ /* s#^[^:]*:[ \t]*##. */
info = buf;
if ((needle = strchr(info, ':'))) {
info = needle + 1;