1 /* assert.cc: Handle the assert macro for WIN32.
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
14 /* This function is called when the assert macro fails. This will
15 override the function of the same name in newlib. */
18 __assert (const char *file
, int line
, const char *failedexpr
)
20 __assert_func (file
, line
, NULL
, failedexpr
);
24 __assert_func (const char *file
, int line
, const char *func
,
25 const char *failedexpr
)
29 /* If we don't have a console in a Windows program, then bring up a
30 message box for the assertion failure. */
32 h
= CreateFile ("CONOUT$", GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
33 &sec_none_nih
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
34 if (h
== INVALID_HANDLE_VALUE
)
36 PWCHAR buf
= (PWCHAR
) alloca ((100 + strlen (failedexpr
))
38 __small_swprintf (buf
,
39 L
"Failed assertion\n\t%s\nat line %d of file %s%s%s",
40 failedexpr
, line
, file
,
41 func
? "\nin function " : "", func
? func
: "");
42 MessageBoxW (NULL
, buf
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
47 small_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
48 failedexpr
, file
, line
,
49 func
? ", function: " : "", func
? func
: "");
50 debug_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s",
51 failedexpr
, file
, line
,
52 func
? ", function: " : "", func
? func
: "");
58 abort (); // FIXME: Someday this should work.