minidlna: update to 1.1.5
[tomato.git] / release / src / router / minidlna / utils.h
blob3a742dd45dcf26053230c04a4d06b01f4dc30f68
1 /* Utility functions
3 * Project : minidlna
4 * Website : http://sourceforge.net/projects/minidlna/
5 * Author : Justin Maggard
7 * MiniDLNA media server
8 * Copyright (C) 2008-2009 Justin Maggard
10 * This file is part of MiniDLNA.
12 * MiniDLNA is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
16 * MiniDLNA is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with MiniDLNA. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef __UTILS_H__
25 #define __UTILS_H__
27 #include <stdarg.h>
28 #include <dirent.h>
29 #include <sys/param.h>
31 #include "minidlnatypes.h"
33 /* String functions */
34 /* We really want this one inlined, since it has a major performance impact */
35 static inline int
36 __attribute__((__format__ (__printf__, 2, 3)))
37 strcatf(struct string_s *str, const char *fmt, ...)
39 int ret;
40 int size;
41 va_list ap;
43 if (str->off >= str->size)
44 return 0;
46 va_start(ap, fmt);
47 size = str->size - str->off;
48 ret = vsnprintf(str->data + str->off, size, fmt, ap);
49 str->off += MIN(ret, size);
50 va_end(ap);
52 return ret;
54 static inline void strncpyt(char *dst, const char *src, size_t len)
56 strncpy(dst, src, len);
57 dst[len-1] = '\0';
59 static inline int is_reg(const struct dirent *d)
61 #if HAVE_STRUCT_DIRENT_D_TYPE
62 return (d->d_type == DT_REG);
63 #else
64 return -1;
65 #endif
67 static inline int is_dir(const struct dirent *d)
69 #if HAVE_STRUCT_DIRENT_D_TYPE
70 return (d->d_type == DT_DIR);
71 #else
72 return -1;
73 #endif
75 int xasprintf(char **strp, char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3)));
76 int ends_with(const char * haystack, const char * needle);
77 char *trim(char *str);
78 char *strstrc(const char *s, const char *p, const char t);
79 char *strcasestrc(const char *s, const char *p, const char t);
80 char *modifyString(char *string, const char *before, const char *after, int noalloc);
81 char *escape_tag(const char *tag, int force_alloc);
82 char *unescape_tag(const char *tag, int force_alloc);
83 char *strip_ext(char *name);
85 /* Metadata functions */
86 int is_video(const char * file);
87 int is_audio(const char * file);
88 int is_image(const char * file);
89 int is_playlist(const char * file);
90 int is_caption(const char * file);
91 int is_album_art(const char * name);
92 int resolve_unknown_type(const char * path, media_types dir_type);
93 const char *mime_to_ext(const char * mime);
95 /* Others */
96 int make_dir(char * path, mode_t mode);
97 unsigned int DJBHash(uint8_t *data, int len);
99 /* Tomato */
100 void begin_scan();
101 void end_scan();
103 #endif