rename internal variables in json_get_type
[project/libubox.git] / utils.h
1 /*
2  * utils - misc libubox utility functions
3  *
4  * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18
19 #ifndef __LIBUBOX_UTILS_H
20 #define __LIBUBOX_UTILS_H
21
22 #include <sys/types.h>
23 #include <sys/time.h>
24 #include <time.h>
25
26 /*
27  * calloc_a(size_t len, [void **addr, size_t len,...], NULL)
28  *
29  * allocate a block of memory big enough to hold multiple aligned objects.
30  * the pointer to the full object (starting with the first chunk) is returned,
31  * all other pointers are stored in the locations behind extra addr arguments.
32  * the last argument needs to be a NULL pointer
33  */
34
35 #define calloc_a(len, ...) __calloc_a(len, ##__VA_ARGS__, NULL)
36
37 void *__calloc_a(size_t len, ...);
38
39 #ifndef ARRAY_SIZE
40 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
41 #endif
42
43 #define __BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
44
45 #ifdef __OPTIMIZE__
46 extern int __BUILD_BUG_ON_CONDITION_FAILED;
47 #define BUILD_BUG_ON(condition)                                 \
48         do {                                                    \
49                 __BUILD_BUG_ON(condition);                      \
50                 if (condition)                                  \
51                         __BUILD_BUG_ON_CONDITION_FAILED = 1;    \
52         } while(0)
53 #else
54 #define BUILD_BUG_ON __BUILD_BUG_ON
55 #endif
56
57 #ifdef __APPLE__
58
59 #define CLOCK_REALTIME  0
60 #define CLOCK_MONOTONIC 1
61
62 void clock_gettime(int type, struct timespec *tv);
63
64 #endif
65
66 #endif