aboutsummaryrefslogtreecommitdiffstatshomepage
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
parent73ef8567f04c2dea8fbf83213b28e0cd1dff98f3 (diff)
downloadcgit-f5c83d7b5ddceb03e1c6bda2e43c48500c7da9f5.tar
cgit-f5c83d7b5ddceb03e1c6bda2e43c48500c7da9f5.tar.gz
cgit-f5c83d7b5ddceb03e1c6bda2e43c48500c7da9f5.zip
move get_mimetype_from_file() to shared
Signed-off-by: Christian Hesse <mail@eworm.de>
-rw-r--r--cgit.h2
-rw-r--r--shared.c40
-rw-r--r--ui-plain.c40
3 files changed, 42 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..fb4e8ca 100644
--- 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;
+}
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;
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378