2 * utils - misc libubox utility functions
4 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
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.
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.
19 #ifndef __LIBUBOX_UTILS_H
20 #define __LIBUBOX_UTILS_H
22 #include <sys/types.h>
27 * calloc_a(size_t len, [void **addr, size_t len,...], NULL)
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
35 #define calloc_a(len, ...) __calloc_a(len, ##__VA_ARGS__, NULL)
37 void *__calloc_a(size_t len, ...);
40 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
43 #define __BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
46 extern int __BUILD_BUG_ON_CONDITION_FAILED;
47 #define BUILD_BUG_ON(condition) \
49 __BUILD_BUG_ON(condition); \
51 __BUILD_BUG_ON_CONDITION_FAILED = 1; \
54 #define BUILD_BUG_ON __BUILD_BUG_ON
59 #define CLOCK_REALTIME 0
60 #define CLOCK_MONOTONIC 1
62 void clock_gettime(int type, struct timespec *tv);