macro.h revision bbc98d32560cc456531bf254f7b69054921082bd
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#ifndef foomacrohfoo
#define foomacrohfoo
/***
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))
#define XSTRINGIFY(x) #x
#define STRINGIFY(x) XSTRINGIFY(x)
/* Rounds up */
}
#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.
*
*/
#ifndef MAX
#define MAX(a,b) \
__extension__ ({ \
})
#endif
#define MAX3(a,b,c) \
#ifndef MIN
#define MIN(a,b) \
__extension__ ({ \
})
#endif
#define MIN3(a,b,c) \
__extension__ ({ \
})
do { \
if (_unlikely_(!(expr))) \
} while (false) \
/* We override the glibc assert() here. */
#ifdef NDEBUG
#else
#endif
#define assert_not_reached(t) \
do { \
} while (false)
do { \
switch (0) { \
case 0: \
case !!(expr): \
; \
} \
} while (false)
#define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p)))
#define UINT_TO_PTR(u) ((void*) ((uintptr_t) (u)))
#define UINT32_TO_PTR(u) ((void*) ((uintptr_t) (u)))
#define PTR_TO_ULONG(p) ((unsigned long) ((uintptr_t) (p)))
#define ULONG_TO_PTR(u) ((void*) ((uintptr_t) (u)))
#define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
#define INT_TO_PTR(u) ((void*) ((intptr_t) (u)))
#define INT32_TO_PTR(u) ((void*) ((intptr_t) (u)))
#define PTR_TO_LONG(p) ((long) ((intptr_t) (p)))
#define LONG_TO_PTR(u) ((void*) ((intptr_t) (u)))
#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;
}
#include "log.h"
#endif