1 /* Copyright (C) 2002 Manuel Novoa III
2 * An __assert() function compatible with the modified glibc assert.h
3 * that is used by uClibc.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, see
17 * <http://www.gnu.org/licenses/>.
18 */
19
20 /* Oct 28, 2002
21 *
22 * ANSI/ISO C99 requires assert() to write to stderr. This means that
23 * writing to STDERR_FILENO is insufficient, as the user could freopen
24 * stderr. It is also insufficient to output to fileno(stderr) since
25 * this would fail in the custom stream case. I didn't remove the
26 * old code though, as it doesn't use stdio stream functionality
27 * and is useful in debugging the stdio code.
28 */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33
34 /* Get the prototype from assert.h as a double-check. */
35 #undef NDEBUG
36 #include <assert.h>
37 #undef assert
38
39
40 #define ASSERT_SHOW_PROGNAME 1
41
42 static smallint in_assert; /* bss inits to 0. */
43
__assert(const char * assertion,const char * filename,unsigned int linenumber,register const char * function)44 void __assert(const char *assertion, const char * filename,
45 unsigned int linenumber, register const char * function)
46 {
47 if (!in_assert) {
48 in_assert = 1;
49
50 fprintf(stderr,
51 #ifdef ASSERT_SHOW_PROGNAME
52 "%s: %s: %d: %s: Assertion `%s' failed.\n", __uclibc_progname,
53 #else
54 "%s: %d: %s: Assertion `%s' failed.\n",
55 #endif
56 filename,
57 linenumber,
58 /* Function name isn't available with some compilers. */
59 ((function == NULL) ? "?function?" : function),
60 assertion
61 );
62 }
63 /* shouldn't we? fflush(stderr); */
64 abort();
65 }
66 libc_hidden_def(__assert)
67