newlib/winsup/cygwin/assert.cc
Corinna Vinschen 6e623e9320 Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option
Bump GPLv2+ to GPLv3+ for some files, clarify BSD 2-clause.

Everything else stays under GPLv3+.

New Linking Exception exempts resulting executables from LGPLv3 section 4.

Add CONTRIBUTORS file to keep track of licensing.

Remove 'Copyright Red Hat Inc' comments.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-06-23 10:09:17 +02:00

62 lines
1.7 KiB
C++

/* assert.cc: Handle the assert macro for WIN32.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <assert.h>
#include <stdlib.h>
/* This function is called when the assert macro fails. This will
override the function of the same name in newlib. */
extern "C" void
__assert (const char *file, int line, const char *failedexpr)
{
__assert_func (file, line, NULL, failedexpr);
}
extern "C" void
__assert_func (const char *file, int line, const char *func,
const char *failedexpr)
{
HANDLE h;
/* If we don't have a console in a Windows program, then bring up a
message box for the assertion failure. */
h = CreateFile ("CONOUT$", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
&sec_none_nih, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE)
{
PWCHAR buf = (PWCHAR) alloca ((100 + strlen (failedexpr))
* sizeof (WCHAR));
__small_swprintf (buf,
L"Failed assertion\n\t%s\nat line %d of file %s%s%s",
failedexpr, line, file,
func ? "\nin function " : "", func ? func : "");
MessageBoxW (NULL, buf, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
}
else
{
CloseHandle (h);
small_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
failedexpr, file, line,
func ? ", function: " : "", func ? func : "");
debug_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s",
failedexpr, file, line,
func ? ", function: " : "", func ? func : "");
}
#ifdef DEBUGGING
try_to_debug ();
#endif
abort (); // FIXME: Someday this should work.
/* NOTREACHED */
}