iPXE
stddef.h
Go to the documentation of this file.
00001 #ifndef STDDEF_H
00002 #define STDDEF_H
00003 
00004 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00005 
00006 #include <stdint.h>
00007 
00008 /** EFI headers also define NULL */
00009 #undef NULL
00010 
00011 /** Null pointer */
00012 #define NULL ( ( void * ) 0 )
00013 
00014 /**
00015  * Get offset of a field within a structure
00016  *
00017  * @v type              Structure type
00018  * @v field             Field within structure
00019  * @ret offset          Offset within structure
00020  */
00021 #if defined ( __GNUC__ ) && ( __GNUC__ > 3 )
00022 #define offsetof( type, field ) __builtin_offsetof ( type, field )
00023 #else
00024 #define offsetof( type, field ) ( ( size_t ) &( ( ( type * ) NULL )->field ) )
00025 #endif
00026 
00027 /**
00028  * Get containing structure
00029  *
00030  * @v ptr               Pointer to contained field
00031  * @v type              Containing structure type
00032  * @v field             Field within containing structure
00033  * @ret container       Pointer to containing structure
00034  */
00035 #define container_of( ptr, type, field ) ( {                            \
00036         type *__container;                                              \
00037         const volatile typeof ( __container->field ) *__field = (ptr);  \
00038         __container = ( ( ( void * ) __field ) -                        \
00039                         offsetof ( type, field ) );                     \
00040         __container; } )
00041 
00042 /* __WCHAR_TYPE__ is defined by gcc and will change if -fshort-wchar is used */
00043 #ifndef __WCHAR_TYPE__
00044 #define __WCHAR_TYPE__ uint16_t
00045 #endif
00046 #ifndef __WINT_TYPE__
00047 #define __WINT_TYPE__ int
00048 #endif
00049 typedef __WCHAR_TYPE__ wchar_t;
00050 typedef __WINT_TYPE__ wint_t;
00051 
00052 #endif /* STDDEF_H */