utils: move ARRAY_SIZE from uloop to utils.h
[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
24 /*
25 * calloc_a(size_t len, [void **addr, size_t len,...], NULL)
26 *
27 * allocate a block of memory big enough to hold multiple aligned objects.
28 * the pointer to the full object (starting with the first chunk) is returned,
29 * all other pointers are stored in the locations behind extra addr arguments.
30 * the last argument needs to be a NULL pointer
31 */
32
33 #define calloc_a(len, ...) __calloc_a(len, ##__VA_ARGS__)
34
35 void *__calloc_a(size_t len, ...);
36
37 #ifndef ARRAY_SIZE
38 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
39 #endif
40
41 #endif