]> diplodocus.org Git - nmh/blobdiff - sbr/mime_type.c
showfile.c: Move interface to own file.
[nmh] / sbr / mime_type.c
index cc6b1fbf58b85da7b14d3a97da3628cc547e6cc1..91c6c3980c8d1c7d77d880c5f5bae63087162964 100644 (file)
@@ -5,9 +5,11 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/utils.h>
-#include <h/tws.h>
+#include "h/mh.h"
+#include "readconfig.h"
+#include "error.h"
+#include "h/utils.h"
+#include "h/tws.h"
 #include "mime_type.h"
 
 #ifdef MIMETYPEPROC
@@ -20,10 +22,10 @@ static char *get_file_info(const char *, const char *);
  * 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;
@@ -55,9 +57,10 @@ mime_type(const char *file_name) {
        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);
        }
@@ -80,16 +83,17 @@ mime_type(const char *file_name) {
 
        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;
                }
            }