Stefan Reinauer | da1ef02 | 2012-12-07 17:24:06 -0800 | [diff] [blame] | 1 | #ifndef STDDEF_H |
| 2 | #define STDDEF_H |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 3 | |
| 4 | typedef long ptrdiff_t; |
Stefan Reinauer | 0e740d3 | 2012-05-14 13:21:08 -0700 | [diff] [blame] | 5 | #ifndef __SIZE_TYPE__ |
| 6 | #define __SIZE_TYPE__ unsigned long |
| 7 | #endif |
| 8 | typedef __SIZE_TYPE__ size_t; |
Stefan Reinauer | f8b3650 | 2013-05-02 14:02:28 -0700 | [diff] [blame] | 9 | /* There is a GCC macro for a size_t type, but not |
| 10 | * for a ssize_t type. Below construct tricks GCC |
| 11 | * into making __SIZE_TYPE__ signed. |
| 12 | */ |
| 13 | #define unsigned signed |
| 14 | typedef __SIZE_TYPE__ ssize_t; |
| 15 | #undef unsigned |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 16 | |
| 17 | typedef int wchar_t; |
| 18 | typedef unsigned int wint_t; |
| 19 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 20 | #define NULL ((void *)0) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 21 | |
Ronald G. Minnich | aa3f428 | 2013-03-15 20:17:26 -0700 | [diff] [blame] | 22 | /* Standard units. */ |
| 23 | #define KiB (1<<10) |
| 24 | #define MiB (1<<20) |
| 25 | #define GiB (1<<30) |
| 26 | /* Could we ever run into this one? I hope we get this much memory! */ |
| 27 | #define TiB (1<<40) |
| 28 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 29 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
| 30 | |
Julius Werner | 03784fa | 2013-12-09 17:46:22 -0800 | [diff] [blame] | 31 | #define check_member(structure, member, offset) _Static_assert( \ |
| 32 | offsetof(struct structure, member) == offset, \ |
| 33 | "`struct " #structure "` offset for `" #member "` is not " #offset ) |
| 34 | |
Stefan Reinauer | 4417deb | 2015-01-05 11:09:11 -0800 | [diff] [blame] | 35 | /** |
| 36 | * container_of - cast a member of a structure out to the containing structure |
| 37 | * @param ptr: the pointer to the member. |
| 38 | * @param type: the type of the container struct this is embedded in. |
| 39 | * @param member: the name of the member within the struct. |
| 40 | * |
| 41 | */ |
| 42 | #define container_of(ptr, type, member) ({ \ |
| 43 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
| 44 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
| 45 | |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 46 | #ifdef __PRE_RAM__ |
| 47 | #define ROMSTAGE_CONST const |
| 48 | #else |
| 49 | #define ROMSTAGE_CONST |
| 50 | #endif |
| 51 | |
Stefan Reinauer | da1ef02 | 2012-12-07 17:24:06 -0800 | [diff] [blame] | 52 | #endif /* STDDEF_H */ |