2000-02-17 20:38:33 +01:00
|
|
|
/* assert.cc: Handle the assert macro for WIN32.
|
|
|
|
|
2001-01-08 05:02:02 +01:00
|
|
|
Copyright 1997, 1998, 2000, 2001 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
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"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "security.h"
|
2000-07-27 19:30:51 +02:00
|
|
|
#include <wingdi.h>
|
|
|
|
#include <winuser.h>
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.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)
|
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
|
|
|
|
/* If we don't have a console in a Windows program, then bring up a
|
|
|
|
message box for the assertion failure. */
|
|
|
|
|
2002-09-19 17:12:48 +02:00
|
|
|
h = CreateFile ("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, &sec_none_nih,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
buf = (char *) alloca (100 + strlen (failedexpr));
|
2000-07-01 19:30:35 +02:00
|
|
|
__small_sprintf (buf, "Failed assertion\n\t%s\nat line %d of file %s",
|
2000-02-17 20:38:33 +01:00
|
|
|
failedexpr, line, file);
|
|
|
|
MessageBox (NULL, buf, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CloseHandle (h);
|
2000-07-01 19:30:35 +02:00
|
|
|
small_printf ("assertion \"%s\" failed: file \"%s\", line %d\n",
|
2000-09-03 06:16:35 +02:00
|
|
|
failedexpr, file, line);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-08-11 21:19:29 +02:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
try_to_debug ();
|
|
|
|
#endif
|
2000-09-03 06:16:35 +02:00
|
|
|
abort (); // FIXME: Someday this should work.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|