1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19: #include <assert.h>
20: #include <libintl.h>
21: #include <stdio.h>
22: #include <stdlib.h>
23: #include <string.h>
24: #include <sysdep.h>
25: #include <unistd.h>
26:
27:
28: extern const char *__progname;
29:
30: #ifdef USE_IN_LIBIO
31: # include <wchar.h>
32: # include <libio/iolibio.h>
33: # define fflush(s) INTUSE(_IO_fflush) (s)
34: #endif
35:
36:
37:
38:
39:
40:
41: #ifdef FATAL_PREPARE_INCLUDE
42: # include FATAL_PREPARE_INCLUDE
43: #endif
44:
45: void
46: __assert_perror_fail (int errnum,
47: const char *file, unsigned int line,
48: const char *function)
49: {
50: char errbuf[1024];
51: char *buf;
52:
53: #ifdef FATAL_PREPARE
54: FATAL_PREPARE;
55: #endif
56:
57: if (__asprintf (&buf, _("%s%s%s:%u: %s%sUnexpected error: %s.\n"),
58: __progname, __progname[0] ? ": " : "",
59: file, line,
60: function ? function : "", function ? ": " : "",
61: __strerror_r (errnum, errbuf, sizeof errbuf)) >= 0)
62: {
63:
64: (void) __fxprintf (NULL, "%s", buf);
65: (void) fflush (stderr);
66:
67:
68:
69: free (buf);
70: }
71: else
72: {
73:
74: static const char errstr[] = "Unexpected error.\n";
75: __libc_write (STDERR_FILENO, errstr, sizeof (errstr) - 1);
76: }
77:
78: abort ();
79: }
80: libc_hidden_def (__assert_perror_fail)