]>
Commit | Line | Data |
---|---|---|
77fe0b9c | 1 | /* Copyright (C) 1991,1994-1996,1998,2001,2002 Free Software Foundation, Inc. |
47707456 | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
47707456 | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
28f540f4 | 8 | |
47707456 UD |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 AJ |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, write to the Free | |
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
17 | 02111-1307 USA. */ | |
28f540f4 | 18 | |
28f540f4 | 19 | #include <assert.h> |
51028f34 | 20 | #include <libintl.h> |
28f540f4 RM |
21 | #include <stdio.h> |
22 | #include <stdlib.h> | |
23 | #include <sysdep.h> | |
383bd1c5 | 24 | #include <unistd.h> |
28f540f4 RM |
25 | |
26 | ||
541587c8 | 27 | extern const char *__progname; |
28f540f4 | 28 | |
50304ef0 | 29 | #ifdef USE_IN_LIBIO |
51028f34 | 30 | # include <wchar.h> |
7a2fd787 | 31 | # include <libio/iolibio.h> |
77fe0b9c | 32 | # define fflush(s) INTUSE(_IO_fflush) (s) |
50304ef0 UD |
33 | #endif |
34 | ||
28f540f4 RM |
35 | /* This function, when passed a string containing an asserted |
36 | expression, a filename, and a line number, prints a message | |
37 | on the standard error stream of the form: | |
38 | a.c:10: foobar: Assertion `a == b' failed. | |
39 | It then aborts program execution via a call to `abort'. */ | |
40 | ||
41 | #ifdef FATAL_PREPARE_INCLUDE | |
50304ef0 | 42 | # include FATAL_PREPARE_INCLUDE |
28f540f4 RM |
43 | #endif |
44 | ||
45 | void | |
47707456 UD |
46 | __assert_fail (const char *assertion, const char *file, unsigned int line, |
47 | const char *function) | |
28f540f4 | 48 | { |
51028f34 UD |
49 | char *buf; |
50 | ||
28f540f4 RM |
51 | #ifdef FATAL_PREPARE |
52 | FATAL_PREPARE; | |
53 | #endif | |
54 | ||
383bd1c5 UD |
55 | if (__asprintf (&buf, _("%s%s%s:%u: %s%sAssertion `%s' failed.\n"), |
56 | __progname, __progname[0] ? ": " : "", | |
57 | file, line, | |
58 | function ? function : "", function ? ": " : "", | |
59 | assertion) >= 0) | |
60 | { | |
61 | /* Print the message. */ | |
51028f34 | 62 | #ifdef USE_IN_LIBIO |
383bd1c5 UD |
63 | if (_IO_fwide (stderr, 0) > 0) |
64 | (void) __fwprintf (stderr, L"%s", buf); | |
65 | else | |
51028f34 | 66 | #endif |
383bd1c5 | 67 | (void) fputs (buf, stderr); |
51028f34 | 68 | |
383bd1c5 | 69 | (void) fflush (stderr); |
28f540f4 | 70 | |
383bd1c5 UD |
71 | /* We have to free the buffer since the appplication might catch the |
72 | SIGABRT. */ | |
73 | free (buf); | |
74 | } | |
75 | else | |
76 | /* At least print a minimal message. */ | |
77 | #define STR_N_LEN(str) str, sizeof (str) - 1 | |
78 | __libc_write (STDERR_FILENO, STR_N_LEN ("Unexpected error.\n")); | |
51028f34 | 79 | |
28f540f4 RM |
80 | abort (); |
81 | } | |
6b87a564 | 82 | INTDEF(__assert_fail) |