macro.h revision ca2871d9b027018c108e0cf7bbc4e5a919e300c3
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#pragma once
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <assert.h>
#include <inttypes.h>
#define _const_ __attribute__ ((const))
#define _unlikely_(x) (__builtin_expect(!!(x),0))
/* automake test harness */
#define EXIT_TEST_SKIP 77
#define XSTRINGIFY(x) #x
#define STRINGIFY(x) XSTRINGIFY(x)
/* Rounds up */
#if __SIZEOF_POINTER__ == 8
#else
#error "Wut? Pointers are neither 4 nor 8 bytes long?"
#endif
#define ALIGN4_PTR(p) ((void*) ALIGN4((unsigned long) p))
#define ALIGN8_PTR(p) ((void*) ALIGN8((unsigned long) p))
}
#define ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0]))
/*
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
__extension__ ({ \
})
#define MAX(a,b) \
__extension__ ({ \
})
#define MAX3(x,y,z) \
__extension__ ({ \
})
#define MIN(a,b) \
__extension__ ({ \
})
#ifndef CLAMP
__extension__ ({ \
})
#endif
do { \
if (_unlikely_(!(expr))) \
} while (false) \
/* We override the glibc assert() here. */
#ifdef NDEBUG
#else
#endif
#define assert_not_reached(t) \
do { \
} while (false)
#if defined(static_assert)
do { \
} while (false)
#else
do { \
switch (0) { \
case 0: \
case !!(expr): \
; \
} \
} while (false)
#endif
#define assert_return(expr, r) \
do { \
if (!(expr)) \
return (r); \
} while (false)
#define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
#define INT_TO_PTR(u) ((void *) ((intptr_t) (u)))
#define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p)))
#define UINT_TO_PTR(u) ((void *) ((uintptr_t) (u)))
#define PTR_TO_LONG(p) ((long) ((intptr_t) (p)))
#define LONG_TO_PTR(u) ((void *) ((intptr_t) (u)))
#define PTR_TO_ULONG(p) ((unsigned long) ((uintptr_t) (p)))
#define ULONG_TO_PTR(u) ((void *) ((uintptr_t) (u)))
#define INT32_TO_PTR(u) ((void *) ((intptr_t) (u)))
#define UINT32_TO_PTR(u) ((void *) ((uintptr_t) (u)))
#define INT64_TO_PTR(u) ((void *) ((intptr_t) (u)))
#define UINT64_TO_PTR(u) ((void *) ((uintptr_t) (u)))
#define CHAR_TO_STR(x) ((char[2]) { x, 0 })
#define char_array_0(x) x[sizeof(x)-1] = 0;
#define IOVEC_SET_STRING(i, s) \
do { \
char *_s = (char *)(s); \
} while(false)
unsigned j;
size_t r = 0;
for (j = 0; j < n; j++)
r += i[j].iov_len;
return r;
}
unsigned j;
for (j = 0; j < n; j++) {
if (_unlikely_(k <= 0))
break;
k -= sub;
}
return k;
}
do { \
int _argtypes[128]; \
continue; \
} \
\
case PA_INT: \
case PA_INT|PA_FLAG_SHORT: \
case PA_CHAR: \
break; \
case PA_INT|PA_FLAG_LONG: \
break; \
case PA_INT|PA_FLAG_LONG_LONG: \
break; \
case PA_WCHAR: \
break; \
case PA_WSTRING: \
case PA_STRING: \
case PA_POINTER: \
break; \
case PA_FLOAT: \
case PA_DOUBLE: \
break; \
case PA_DOUBLE|PA_FLAG_LONG_DOUBLE: \
break; \
default: \
assert_not_reached("Unknown format string argument."); \
} \
} \
} while(false)
/* Because statfs.t_type can be int on some architecures, we have to cast
* the const magic to the type, otherwise the compiler warns about
*/
#define F_TYPE_EQUAL(a, b) (a == (typeof(a)) b)
/* Returns the number of chars needed to format variables of the
* specified type as a decimal string. Adds in extra space for a
* negative '-' prefix. */
#define DECIMAL_STR_MAX(type) \
#include "log.h"