]> git.ipfire.org Git - thirdparty/glibc.git/blob - assert/assert.h
Update.
[thirdparty/glibc.git] / assert / assert.h
1 /* Copyright (C) 1991,92,94,95,96,97,98,99 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 # ifdef __USE_GNU
29 # undef assert_perror
30 # endif
31
32 #endif /* assert.h */
33
34 #define _ASSERT_H 1
35 #include <features.h>
36
37 /* void assert (int expression);
38
39 If NDEBUG is defined, do nothing.
40 If not, and EXPRESSION is zero, print an error message and abort. */
41
42 #ifdef NDEBUG
43
44 # define assert(expr) ((void) 0)
45
46 /* void assert_perror (int errnum);
47
48 If NDEBUG is defined, do nothing. If not, and ERRNUM is not zero, print an
49 error message with the error text for ERRNUM and abort.
50 (This is a GNU extension.) */
51
52 # ifdef __USE_GNU
53 # define assert_perror(errnum) ((void) 0)
54 # endif
55
56 #else /* Not NDEBUG. */
57
58 __BEGIN_DECLS
59
60 /* This prints an "Assertion failed" message and aborts. */
61 extern void __assert_fail __P ((__const char *__assertion,
62 __const char *__file,
63 unsigned int __line,
64 __const char *__function))
65 __attribute__ ((__noreturn__));
66
67 /* Likewise, but prints the error text for ERRNUM. */
68 extern void __assert_perror_fail __P ((int __errnum,
69 __const char *__file,
70 unsigned int __line,
71 __const char *__function))
72 __attribute__ ((__noreturn__));
73
74 __END_DECLS
75
76 # define assert(expr) \
77 ((void) ((expr) ? 0 : \
78 (__assert_fail (__STRING(expr), \
79 __FILE__, __LINE__, __ASSERT_FUNCTION), 0)))
80
81 # ifdef __USE_GNU
82 # define assert_perror(errnum) \
83 ((void) (!(errnum) ? 0 : (__assert_perror_fail ((errnum), \
84 __FILE__, __LINE__, \
85 __ASSERT_FUNCTION), 0)))
86 # endif
87
88 /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
89 which contains the name of the function currently being defined.
90 This is broken in G++ before version 2.6.
91 C9x has a similar variable called __func__, but prefer the GCC one since
92 it demangles C++ function names. */
93 # if __GNUC_PREREQ (2, (defined __cplusplus ? 6 : 4))
94 # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
95 # else
96 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
97 # define __ASSERT_FUNCTION __func__
98 # else
99 # define __ASSERT_FUNCTION ((__const char *) 0)
100 # endif
101 # endif
102
103 #endif /* NDEBUG. */