OSDN Git Service

* path.cc (conv_path_list): Take cygwin_conv_path_t as third parameter.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / assert.cc
1 /* assert.cc: Handle the assert macro for WIN32.
2
3    Copyright 1997, 1998, 2000, 2001, 2007, 2008, 2009, 2011 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #include "winsup.h"
12 #include <wingdi.h>
13 #include <winuser.h>
14
15 #include <assert.h>
16 #include <stdlib.h>
17
18 /* This function is called when the assert macro fails.  This will
19    override the function of the same name in newlib.  */
20
21 extern "C" void
22 __assert (const char *file, int line, const char *failedexpr)
23 {
24   __assert_func (file, line, NULL, failedexpr);
25 }
26
27 extern "C" void
28 __assert_func (const char *file, int line, const char *func,
29                const char *failedexpr)
30 {
31   HANDLE h;
32
33   /* If we don't have a console in a Windows program, then bring up a
34      message box for the assertion failure.  */
35
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)
39     {
40       PWCHAR buf = (PWCHAR) alloca ((100 + strlen (failedexpr))
41                                     * sizeof (WCHAR));
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);
47     }
48   else
49     {
50       CloseHandle (h);
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 : "");
57     }
58
59 #ifdef DEBUGGING
60   try_to_debug ();
61 #endif
62   abort ();     // FIXME: Someday this should work.
63
64   /* NOTREACHED */
65 }