4 * Website : http://sourceforge.net/projects/minidlna/
5 * Author : Justin Maggard
7 * MiniDLNA media server
8 * Copyright (C) 2008-2017 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/>.
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 */
36 __attribute__((__format__ (__printf__
, 2, 3)))
37 strcatf(struct string_s
*str
, const char *fmt
, ...)
43 if (str
->off
>= str
->size
)
47 size
= str
->size
- str
->off
;
48 ret
= vsnprintf(str
->data
+ str
->off
, size
, fmt
, ap
);
49 str
->off
+= MIN(ret
, size
);
54 static inline void strncpyt(char *dst
, const char *src
, size_t len
)
56 strncpy(dst
, src
, --len
);
59 static inline int is_reg(const struct dirent
*d
)
61 #if HAVE_STRUCT_DIRENT_D_TYPE
62 return (d
->d_type
== DT_REG
);
67 static inline int is_dir(const struct dirent
*d
)
69 #if HAVE_STRUCT_DIRENT_D_TYPE
70 return (d
->d_type
== DT_DIR
);
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 *duration_str(int msec
);
84 char *strip_ext(char *name
);
86 /* Metadata functions */
87 int is_video(const char * file
);
88 int is_audio(const char * file
);
89 int is_image(const char * file
);
90 int is_playlist(const char * file
);
91 int is_caption(const char * file
);
92 #define is_nfo(file) ends_with(file, ".nfo")
93 media_types
get_media_type(const char *file
);
94 media_types
valid_media_types(const char *path
);
96 int is_album_art(const char * name
);
97 int resolve_unknown_type(const char * path
, media_types dir_type
);
98 const char *mime_to_ext(const char * mime
);
101 int make_dir(char * path
, mode_t mode
);
102 unsigned int DJBHash(uint8_t *data
, int len
);
104 /* Timeval manipulations */
105 void timevaladd(struct timeval
*t1
, const struct timeval
*t2
);
106 void timevalsub(struct timeval
*t1
, const struct timeval
*t2
);
107 #define timevalcmp(tvp, uvp, cmp) \
108 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
109 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
110 ((tvp)->tv_sec cmp (uvp)->tv_sec))