update from main archive 961030
[platform/upstream/glibc.git] / assert / assert.h
1 /* Copyright (C) 1991, 92, 94, 95, 96 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public
15    License along with the GNU C Library; see the file COPYING.LIB.  If not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18
19 /*
20  *      ISO C Standard: 4.2 DIAGNOSTICS <assert.h>
21  */
22
23 #ifdef  _ASSERT_H
24
25 #undef  _ASSERT_H
26 #undef  assert
27
28 #endif /* assert.h      */
29
30 #define _ASSERT_H       1
31 #include <features.h>
32
33 /* void assert (int expression);
34
35    If NDEBUG is defined, do nothing.
36    If not, and EXPRESSION is zero, print an error message and abort.  */
37
38 #ifdef  NDEBUG
39
40 #define assert(expr)            ((void) 0)
41
42 /* void assert_perror (int errnum);
43
44    If NDEBUG is defined, do nothing.  If not, and ERRNUM is not zero, print an
45    error message with the error text for ERRNUM and abort.
46    (This is a GNU extension.) */
47
48 #ifdef  __USE_GNU
49 #define assert_perror(errnum)   ((void) 0)
50 #endif
51
52 #else /* Not NDEBUG.  */
53
54 #include <sys/cdefs.h>
55
56 __BEGIN_DECLS
57
58 /* This prints an "Assertion failed" message and aborts.  */
59 extern void __assert_fail __P ((__const char *__assertion,
60                                 __const char *__file,
61                                 unsigned int __line,
62                                 __const char *__function))
63      __attribute__ ((__noreturn__));
64
65 /* Likewise, but prints the error text for ERRNUM.  */
66 extern void __assert_perror_fail __P ((int __errnum,
67                                        __const char *__file,
68                                        unsigned int __line,
69                                        __const char *__function))
70      __attribute__ ((__noreturn__));
71
72 __END_DECLS
73
74 #define assert(expr)                                                          \
75   ((void) ((expr) ||                                                          \
76            (__assert_fail (__STRING(expr),                                    \
77                            __FILE__, __LINE__, __ASSERT_FUNCTION), 0)))
78
79 #ifdef  __USE_GNU
80 #define assert_perror(errnum)                                                 \
81   ((void) ((errnum) && (__assert_perror_fail ((errnum),                       \
82                                               __FILE__, __LINE__,             \
83                                               __ASSERT_FUNCTION), 0)))
84 #endif
85
86 /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
87    which contains the name of the function currently being defined.
88    This is broken in G++ before version 2.6.  */
89 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
90      __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
91 #define __ASSERT_FUNCTION       ((__const char *) 0)
92 #else
93 #define __ASSERT_FUNCTION       __PRETTY_FUNCTION__
94 #endif
95
96
97 #endif /* NDEBUG.  */