From: list at eworm.de (Christian Hesse)
Subject: [PATCH 1/2] move get_mimetype_from_file() to shared
Date: Fri, 14 Aug 2015 16:50:56 +0200 [thread overview]
Message-ID: <1439563857-32527-1-git-send-email-list@eworm.de> (raw)
From: Christian Hesse <mail at eworm.de>
Signed-off-by: Christian Hesse <mail at eworm.de>
---
cgit.h | 2 ++
shared.c | 41 +++++++++++++++++++++++++++++++++++++++++
ui-plain.c | 40 ----------------------------------------
3 files changed, 43 insertions(+), 40 deletions(-)
diff --git a/cgit.h b/cgit.h
index f327627..0f1e186 100644
--- 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 */
diff --git a/shared.c b/shared.c
index 3bd2a9e..5a000a6 100644
--- a/shared.c
+++ b/shared.c
@@ -560,3 +560,44 @@ 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;
+}
+
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 {
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;
--
2.5.0
next reply other threads:[~2015-08-14 14:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-14 14:50 list [this message]
2015-08-14 14:50 ` [PATCH 2/2] about: send images plain list
2015-08-14 15:13 ` john
2015-08-14 21:16 ` [PATCH 2/3] " list
2015-08-14 21:16 ` [PATCH 3/3] move shared code to get_mimetype_from_file() list
2015-08-15 11:29 ` john
2015-08-15 20:12 ` list
2015-08-14 23:07 ` [PATCH 2/3] about: send images plain Jason
2015-08-15 20:10 ` list
2015-08-15 11:30 ` john
2015-08-15 20:08 ` [PATCH 2/3] refactor get_mimetype_from_file() to get_mimetype_from_qrypath() list
2015-08-15 20:08 ` [PATCH 3/3] ui-summary: send images plain for about page list
2015-08-16 12:19 ` [PATCH 2/3] refactor get_mimetype_from_file() to get_mimetype_from_qrypath() john
2015-08-16 12:51 ` list
2015-08-16 12:53 ` [PATCH 2/3] refactor get_mimetype_from_file() to get_mimetype_for_filename() list
2015-08-16 12:53 ` [PATCH 3/3] ui-summary: send images plain for about page list
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1439563857-32527-1-git-send-email-list@eworm.de \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).