1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 #include <sys/param.h>
30 #include <sys/types.h>
34 #define _printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
35 #define _alloc_(...) __attribute__ ((alloc_size(__VA_ARGS__)))
36 #define _sentinel_ __attribute__ ((sentinel))
37 #define _noreturn_ __attribute__((noreturn))
38 #define _unused_ __attribute__ ((unused))
39 #define _destructor_ __attribute__ ((destructor))
40 #define _pure_ __attribute__ ((pure))
41 #define _const_ __attribute__ ((const))
42 #define _deprecated_ __attribute__ ((deprecated))
43 #define _packed_ __attribute__ ((packed))
44 #define _malloc_ __attribute__ ((malloc))
45 #define _weak_ __attribute__ ((weak))
46 #define _likely_(x) (__builtin_expect(!!(x),1))
47 #define _unlikely_(x) (__builtin_expect(!!(x),0))
48 #define _public_ __attribute__ ((visibility("default")))
49 #define _hidden_ __attribute__ ((visibility("hidden")))
50 #define _weakref_(x) __attribute__((weakref(#x)))
51 #define _introspect_(x) __attribute__((section("introspect." x)))
52 #define _alignas_(x) __attribute__((aligned(__alignof(x))))
53 #define _cleanup_(x) __attribute__((cleanup(x)))
57 #define ALIGN4(l) (((l) + 3) & (unsigned)~3)
58 #define ALIGN8(l) (((l) + 7) & (unsigned)~7)
60 #if __SIZEOF_POINTER__ == 8
61 #define ALIGN(l) ALIGN8(l)
62 #elif __SIZEOF_POINTER__ == 4
63 #define ALIGN(l) ALIGN4(l)
65 #error "Wut? Pointers are neither 4 nor 8 bytes long?"
68 #define ALIGN_PTR(p) ((void*) ALIGN((unsigned long) p))
69 #define ALIGN4_PTR(p) ((void*) ALIGN4((unsigned long) p))
70 #define ALIGN8_PTR(p) ((void*) ALIGN8((unsigned long) p))
72 static inline size_t ALIGN_TO(size_t l, size_t ali) {
73 return ((l + ali - 1) & (unsigned)~(ali - 1));
76 #define ALIGN_TO_PTR(p, ali) ((void*) ALIGN_TO((unsigned long) p))
78 #define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
79 #define INT_TO_PTR(u) ((void *) ((intptr_t) (u)))
80 #define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p)))
81 #define UINT_TO_PTR(u) ((void *) ((uintptr_t) (u)))
83 #define memzero(x,l) (memset((x), 0, (l)))