Blame uwac/libuwac/uwac-utils.h

Packit Service fa4841
/*
Packit Service fa4841
 * Copyright © 2014 David FORT <contact@hardening-consulting.com>
Packit Service fa4841
 *
Packit Service fa4841
 * Permission to use, copy, modify, distribute, and sell this software and its
Packit Service fa4841
 * documentation for any purpose is hereby granted without fee, provided that
Packit Service fa4841
 * the above copyright notice appear in all copies and that both that copyright
Packit Service fa4841
 * notice and this permission notice appear in supporting documentation, and
Packit Service fa4841
 * that the name of the copyright holders not be used in advertising or
Packit Service fa4841
 * publicity pertaining to distribution of the software without specific,
Packit Service fa4841
 * written prior permission.  The copyright holders make no representations
Packit Service fa4841
 * about the suitability of this software for any purpose.  It is provided "as
Packit Service fa4841
 * is" without express or implied warranty.
Packit Service fa4841
 *
Packit Service fa4841
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
Packit Service fa4841
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
Packit Service fa4841
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
Packit Service fa4841
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
Packit Service fa4841
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
Packit Service fa4841
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
Packit Service fa4841
 * OF THIS SOFTWARE.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#ifndef UWAC_UTILS_H_
Packit Service fa4841
#define UWAC_UTILS_H_
Packit Service fa4841
Packit Service fa4841
#include <stdlib.h>
Packit Service fa4841
Packit Service fa4841
#define min(a, b)               \
Packit Service fa4841
	({                          \
Packit Service fa4841
		__typeof__(a) _a = (a); \
Packit Service fa4841
		__typeof__(b) _b = (b); \
Packit Service fa4841
		_a < _b ? _a : _b;      \
Packit Service fa4841
	})
Packit Service fa4841
Packit Service fa4841
#define container_of(ptr, type, member)                       \
Packit Service fa4841
	({                                                        \
Packit Service fa4841
		const __typeof__(((type*)0)->member)* __mptr = (ptr); \
Packit Service fa4841
		(type*)((char*)__mptr - offsetof(type, member));      \
Packit Service fa4841
	})
Packit Service fa4841
Packit Service fa4841
#define ARRAY_LENGTH(a) (sizeof(a) / sizeof(a)[0])
Packit Service fa4841
Packit Service fa4841
void* xmalloc(size_t s);
Packit Service fa4841
Packit Service fa4841
static inline void* zalloc(size_t size)
Packit Service fa4841
{
Packit Service fa4841
	return calloc(1, size);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
void* xzalloc(size_t s);
Packit Service fa4841
Packit Service fa4841
char* xstrdup(const char* s);
Packit Service fa4841
Packit Service fa4841
void* xrealloc(void* p, size_t s);
Packit Service fa4841
Packit Service fa4841
#endif /* UWAC_UTILS_H_ */