1 /* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License, version 2, as 4 * published by the Free Software Foundation. 5 * 6 * This program is distributed in the hope that it will be useful, 7 * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 * GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License 12 * along with this program; if not, write to the Free Software 13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 14 * 15 * Copyright IBM Corp. 2008 16 * 17 * Authors: Hollis Blanchard <hollisb@us.ibm.com> 18 */ 19 20 #ifndef __LIBCFLAT_H 21 #define __LIBCFLAT_H 22 23 #include <stdarg.h> 24 #include <stddef.h> 25 #include <stdint.h> 26 #include <string.h> 27 28 #define xstr(s) xxstr(s) 29 #define xxstr(s) #s 30 31 typedef uint8_t u8; 32 typedef int8_t s8; 33 typedef uint16_t u16; 34 typedef int16_t s16; 35 typedef uint32_t u32; 36 typedef int32_t s32; 37 typedef uint64_t u64; 38 typedef int64_t s64; 39 typedef unsigned long ulong; 40 41 typedef _Bool bool; 42 #define false 0 43 #define true 1 44 45 extern void puts(const char *s); 46 extern void exit(int code); 47 extern void abort(void); 48 49 extern int printf(const char *fmt, ...); 50 extern int snprintf(char *buf, int size, const char *fmt, ...); 51 extern int vsnprintf(char *buf, int size, const char *fmt, va_list va); 52 extern long atol(const char *ptr); 53 54 void report(const char *msg_fmt, bool pass, ...); 55 void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...); 56 int report_summary(void); 57 58 #define ARRAY_SIZE(_a) (sizeof(_a)/sizeof((_a)[0])) 59 60 #define container_of(ptr, type, member) ({ \ 61 const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 62 (type *)( (char *)__mptr - offsetof(type,member) );}) 63 64 #define assert(cond) \ 65 do { \ 66 if (!(cond)) \ 67 printf("%s:%d: assert failed\n", __FILE__, __LINE__), \ 68 abort(); \ 69 } while (0) 70 71 #endif 72