Cygwin: (mostly) drop NT4 and Samba < 3.0 support
[newlib-cygwin.git] / winsup / cygwin / assert.cc
blobd78e6e7d242dbac374920d853bc366c74aca7a1a
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
7 details. */
9 #include "winsup.h"
11 #include <assert.h>
12 #include <stdlib.h>
14 /* This function is called when the assert macro fails. This will
15 override the function of the same name in newlib. */
17 extern "C" void
18 __assert (const char *file, int line, const char *failedexpr)
20 __assert_func (file, line, NULL, failedexpr);
23 extern "C" void
24 __assert_func (const char *file, int line, const char *func,
25 const char *failedexpr)
27 HANDLE h;
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))
37 * sizeof (WCHAR));
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);
44 else
46 CloseHandle (h);
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 : "");
55 #ifdef DEBUGGING
56 try_to_debug ();
57 #endif
58 abort (); // FIXME: Someday this should work.
60 /* NOTREACHED */