diff options
author | Michael Brown | 2006-03-23 18:28:51 +0100 |
---|---|---|
committer | Michael Brown | 2006-03-23 18:28:51 +0100 |
commit | cb8e89de1579d64b45f08f8eac73f9152f4f44e8 (patch) | |
tree | b8e60dfc47441d4e0b7eeac0be678f081af8b5b3 /src/include/assert.h | |
parent | Removed to make way for the uIP-based tcp.c. (diff) | |
download | ipxe-cb8e89de1579d64b45f08f8eac73f9152f4f44e8.tar.gz ipxe-cb8e89de1579d64b45f08f8eac73f9152f4f44e8.tar.xz ipxe-cb8e89de1579d64b45f08f8eac73f9152f4f44e8.zip |
Added assert.h, with assert() defined (almost) as per POSIX, and
linker_assert() defined as gPXE-specific.
Diffstat (limited to 'src/include/assert.h')
-rw-r--r-- | src/include/assert.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/include/assert.h b/src/include/assert.h new file mode 100644 index 00000000..b4dfe128 --- /dev/null +++ b/src/include/assert.h @@ -0,0 +1,51 @@ +#ifndef _ASSERT_H +#define _ASSERT_H + +/** @file + * + * Assertions + * + * This file provides two assertion macros: assert() (for run-time + * assertions) and linker_assert() (for link-time assertions). + * + */ + +/** + * Assert a condition at run-time. + * + * If the condition is not true, a debug message will be printed. + * Assertions only take effect in debug-enabled builds (see DBG()). + * + * @todo Make an assertion failure abort the program + * + */ +#define assert( condition ) \ + do { \ + if ( ! (condition) ) { \ + printf ( "assert(%s) failed at %s line %d [%s]\n", \ + #condition, __FILE__, __LINE__, \ + __FUNCTION__ ); \ + } \ + } while ( 0 ) + +/** + * Assert a condition at link-time. + * + * If the condition is not true, the link will fail with an unresolved + * symbol (error_symbol). + * + * This macro is gPXE-specific. Do not use this macro in code + * intended to be portable. + * + */ +#define linker_assert( condition, error_symbol ) \ + if ( ! (condition) ) { \ + extern void error_symbol ( void ); \ + error_symbol(); \ + } + +#ifdef NDEBUG +#undef assert +#define assert(x) do {} while ( 0 ) + +#endif /* _ASSERT_H */ |