Welcome to mirror list, hosted at ThFree Co, Russian Federation.

assert.cc « cygwin « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a47a3827f8eff419289c2902dd7bd0510e1eecde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* assert.cc: Handle the assert macro for WIN32.

   Copyright 1997, 1998, 2000, 2001, 2007, 2008, 2009 Red Hat, Inc.

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 <wingdi.h>
#include <winuser.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_WRITE, &sec_none_nih,
		  OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  if (h == INVALID_HANDLE_VALUE)
    {
      char *buf;

      buf = (char *) alloca (100 + strlen (failedexpr));
      __small_sprintf (buf, "Failed assertion\n\t%s\nat line %d of file %s%s%s",
		       failedexpr, line, file,
		       func ? "\nin function " : "", func ? func : "");
      MessageBox (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 : "");
    }

#ifdef DEBUGGING
  try_to_debug ();
#endif
  abort ();	// FIXME: Someday this should work.

  /* NOTREACHED */
}