]> git.cameronkatri.com Git - cgit.git/commitdiff
move get_mimetype_from_file() to shared
authorChristian Hesse <mail@eworm.de>
Fri, 14 Aug 2015 14:50:56 +0000 (16:50 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Mon, 17 Aug 2015 12:25:08 +0000 (14:25 +0200)
Signed-off-by: Christian Hesse <mail@eworm.de>
cgit.h
shared.c
ui-plain.c

diff --git a/cgit.h b/cgit.h
index f3276276fe2c258ae802d8c0351422affb1f468d..0f1e18626e9d2d134fd593b696b1a5fe4a7daccd 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -391,4 +391,6 @@ extern int readfile(const char *path, char **buf, size_t *size);
 
 extern char *expand_macros(const char *txt);
 
+extern char *get_mimetype_from_file(const char *filename, const char *ext);
+
 #endif /* CGIT_H */
index 3bd2a9e3dadd39282712f297218433cdfcdb34d1..fb4e8ca642d4b3c3f988b30f5c1487ad952edb44 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -560,3 +560,43 @@ char *expand_macros(const char *txt)
        }
        return result;
 }
+
+char *get_mimetype_from_file(const char *filename, const char *ext)
+{
+       static const char *delimiters;
+       char *result;
+       FILE *fd;
+       char line[1024];
+       char *mimetype;
+       char *token;
+
+       if (!filename)
+               return NULL;
+
+       fd = fopen(filename, "r");
+       if (!fd)
+               return NULL;
+
+       delimiters = " \t\r\n";
+       result = NULL;
+
+       /* loop over all lines in the file */
+       while (!result && fgets(line, sizeof(line), fd)) {
+               mimetype = strtok(line, delimiters);
+
+               /* skip empty lines and comment lines */
+               if (!mimetype || (mimetype[0] == '#'))
+                       continue;
+
+               /* loop over all extensions of mimetype */
+               while ((token = strtok(NULL, delimiters))) {
+                       if (!strcasecmp(ext, token)) {
+                               result = xstrdup(mimetype);
+                               break;
+                       }
+               }
+       }
+       fclose(fd);
+
+       return result;
+}
index 0daa7bf062db66683f9e7ae107feb20f07973183..d68518e1771a7ed10c6b52d42dc5aaf9a469daf4 100644 (file)
@@ -16,46 +16,6 @@ struct walk_tree_context {
        int match;
 };
 
-static char *get_mimetype_from_file(const char *filename, const char *ext)
-{
-       static const char *delimiters;
-       char *result;
-       FILE *fd;
-       char line[1024];
-       char *mimetype;
-       char *token;
-
-       if (!filename)
-               return NULL;
-
-       fd = fopen(filename, "r");
-       if (!fd)
-               return NULL;
-
-       delimiters = " \t\r\n";
-       result = NULL;
-
-       /* loop over all lines in the file */
-       while (!result && fgets(line, sizeof(line), fd)) {
-               mimetype = strtok(line, delimiters);
-
-               /* skip empty lines and comment lines */
-               if (!mimetype || (mimetype[0] == '#'))
-                       continue;
-
-               /* loop over all extensions of mimetype */
-               while ((token = strtok(NULL, delimiters))) {
-                       if (!strcasecmp(ext, token)) {
-                               result = xstrdup(mimetype);
-                               break;
-                       }
-               }
-       }
-       fclose(fd);
-
-       return result;
-}
-
 static int print_object(const unsigned char *sha1, const char *path)
 {
        enum object_type type;