about summary refs log tree commit diff stats
path: root/ui-plain.c
diff options
context:
space:
mode:
authorChristian Hesse2015-08-14 16:50:56 +0200
committerJason A. Donenfeld2015-08-17 14:25:08 +0200
commitf5c83d7b5ddceb03e1c6bda2e43c48500c7da9f5 (patch)
tree7c14ef706458087fabc88ad307a70cdb22df367c /ui-plain.c
parentcmd: fix command definition (diff)
downloadcgit-f5c83d7b5ddceb03e1c6bda2e43c48500c7da9f5.tar.gz
cgit-f5c83d7b5ddceb03e1c6bda2e43c48500c7da9f5.zip
move get_mimetype_from_file() to shared
Signed-off-by: Christian Hesse <mail@eworm.de>
Diffstat (limited to 'ui-plain.c')
-rw-r--r--ui-plain.c40
1 files changed, 0 insertions, 40 deletions
diff --git a/ui-plain.c b/ui-plain.c index 0daa7bf..d68518e 100644 --- a/ui-plain.c +++ b/ui-plain.c
@@ -16,46 +16,6 @@ struct walk_tree_context {
16 int match; 16 int match;
17}; 17};
18 18
19static char *get_mimetype_from_file(const char *filename, const char *ext)
20{
21 static const char *delimiters;
22 char *result;
23 FILE *fd;
24 char line[1024];
25 char *mimetype;
26 char *token;
27
28 if (!filename)
29 return NULL;
30
31 fd = fopen(filename, "r");
32 if (!fd)
33 return NULL;
34
35 delimiters = " \t\r\n";
36 result = NULL;
37
38 /* loop over all lines in the file */
39 while (!result && fgets(line, sizeof(line), fd)) {
40 mimetype = strtok(line, delimiters);
41
42 /* skip empty lines and comment lines */
43 if (!mimetype || (mimetype[0] == '#'))
44 continue;
45
46 /* loop over all extensions of mimetype */
47 while ((token = strtok(NULL, delimiters))) {
48 if (!strcasecmp(ext, token)) {
49 result = xstrdup(mimetype);
50 break;
51 }
52 }
53 }
54 fclose(fd);
55
56 return result;
57}
58
59static int print_object(const unsigned char *sha1, const char *path) 19static int print_object(const unsigned char *sha1, const char *path)
60{ 20{
61 enum object_type type; 21 enum object_type type;