1 /* assert.cc: Handle the assert macro for WIN32.
3 Copyright 1997, 1998, 2000, 2001, 2007, 2008, 2009, 2011 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
18 /* This function is called when the assert macro fails. This will
19 override the function of the same name in newlib. */
22 __assert (const char *file, int line, const char *failedexpr)
24 __assert_func (file, line, NULL, failedexpr);
28 __assert_func (const char *file, int line, const char *func,
29 const char *failedexpr)
33 /* If we don't have a console in a Windows program, then bring up a
34 message box for the assertion failure. */
36 h = CreateFile ("CONOUT$", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
37 &sec_none_nih, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
38 if (h == INVALID_HANDLE_VALUE)
40 PWCHAR buf = (PWCHAR) alloca ((100 + strlen (failedexpr))
42 __small_swprintf (buf,
43 L"Failed assertion\n\t%s\nat line %d of file %s%s%s",
44 failedexpr, line, file,
45 func ? "\nin function " : "", func ? func : "");
46 MessageBoxW (NULL, buf, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
51 small_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
52 failedexpr, file, line,
53 func ? ", function: " : "", func ? func : "");
54 debug_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s",
55 failedexpr, file, line,
56 func ? ", function: " : "", func ? func : "");
62 abort (); // FIXME: Someday this should work.