utils refactor.
[platform/upstream/lightmediascanner.git] / src / lib / lightmediascanner_utils.h
1 /**
2  * Copyright (C) 2007 by INdT
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
19  */
20
21 #ifndef _LIGHTMEDIASCANNER_UTILS_H_
22 #define _LIGHTMEDIASCANNER_UTILS_H_ 1
23
24 #ifdef API
25 #undef API
26 #endif
27
28 #ifdef __GNUC__
29 # if __GNUC__ >= 4
30 #  define API __attribute__ ((visibility("default")))
31 # else
32 #  define API
33 # endif
34 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
35 #  define GNUC_NON_NULL(...) __attribute__((nonnull(__VA_ARGS__)))
36 # else
37 #  define GNUC_NON_NULL(...)
38 # endif
39 #else
40 #  define API
41 #  define GNUC_NON_NULL(...)
42 #endif
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #include <lightmediascanner_charset_conv.h>
49
50     struct lms_string_size {
51         char *str;
52         unsigned int len;
53     };
54
55 #define LMS_STATIC_STRING_SIZE(s) ((struct lms_string_size) { (char *)s, sizeof(s) - 1})
56 #define LMS_ARRAY_SIZE(a)  (sizeof(a) / sizeof(*a))
57
58
59     API void lms_strstrip(char *str, unsigned int *p_len) GNUC_NON_NULL(1, 2);
60     API void lms_strstrip_and_free(char **p_str, unsigned int *p_len) GNUC_NON_NULL(1, 2);
61     API void lms_string_size_strip_and_free(struct lms_string_size *p) GNUC_NON_NULL(1);
62
63     API int lms_string_size_dup(struct lms_string_size *dst, const struct lms_string_size *src) GNUC_NON_NULL(1, 2);
64     API int lms_string_size_strndup(struct lms_string_size *dst, const char *src, int size) GNUC_NON_NULL(1);
65
66     API int lms_aspect_ratio_guess(struct lms_string_size *ret, int width, int height) GNUC_NON_NULL(1);
67
68     API int lms_which_extension(const char *name, unsigned int name_len, const struct lms_string_size *exts, unsigned int exts_len) GNUC_NON_NULL(1, 3);
69
70     API int lms_name_from_path(struct lms_string_size *name, const char *path, unsigned int pathlen, unsigned int baselen, unsigned int extlen, struct lms_charset_conv *cs_conv) GNUC_NON_NULL(1, 2);
71
72
73 #ifdef __cplusplus
74 }
75 #endif
76 #endif /* _LIGHTMEDIASCANNER_UTILS_H_ */