[libposix-development] [PATCH] Assert.h, assert macro
Status: Pre-Alpha
Brought to you by:
hdante
From: Tordek <ke...@gm...> - 2009-07-01 03:16:50
|
Signed-off-by: Guillermo O. Freschi <to...@to...> --- mandatory/include/assert.h | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-) create mode 100644 mandatory/include/assert.h diff --git a/mandatory/include/assert.h b/mandatory/include/assert.h new file mode 100644 index 0000000..20c0f8f --- /dev/null +++ b/mandatory/include/assert.h @@ -0,0 +1,51 @@ +/* +Copyright (c) 2009, Guillermo Oscar Freschi +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _ASSERT_H_INCLUDED_ +#define _ASSERT_H_INCLUDED_ + +#ifdef NDEBUG +#define assert(ignore)((void) 0) +#else + +// Temporal hack to show line numbers. Should be removed when +// printf is fully functional. +#define _ITOA_(num) #num +#define _ITOA(num) _ITOA_(num) + +#define assert(assertion) \ + do { \ + if(!(assertion)) { \ + puts("Assertion failed in file " __FILE__ ", "\ + "line " _ITOA(__LINE__) ": "\ + #assertion); \ + _Exit(EXIT_FAILURE); \ + } \ + } while(0) + +#endif /* NDEBUG */ + +#endif /* _ASSERT_H_INCLUDED_ */ -- 1.6.3.3 -- Guillermo O. «Tordek» Freschi. Programador, Escritor, Genio Maligno. http://tordek.com.ar :: http://twitter.com/tordek http://www.arcanopedia.com.ar - Juegos de Rol en Argentina |