libc/winsup/cygwin/assert.cc
Corinna Vinschen ebbd4e8fb3 Changes by Kazuhiro Fujieda <fujieda@jaist.ac.jp>
* assert.cc (__assert): Reduce dependency on newlib.
        * exec.cc: Eliminate unnecessary inclusion of ctype.h.
        * glob.c: Ditto.
        * hinfo.cc: Ditto.
        * init.cc: Ditto.
        * strace.cc: Ditto.
        * tty.cc: Ditto.
        * grp.cc (parse_grp): Eliminate atoi.
        * passwd.cc (grab_int): Ditto.
        * grp.cc (getgroups): Eliminate str{n,}casecmp.
        * path.cc (get_raw_device_number): Ditto.
        * path.cc (sort_by_native_name): Ditto.
        * spawn.cc (iscmd): Ditto.
        * uinfo.cc (internal_getlogin): Ditto.
2000-07-01 17:30:35 +00:00

50 lines
1.3 KiB
C++

/* assert.cc: Handle the assert macro for WIN32.
Copyright 1997, 1998, 2000 Cygnus Solutions.
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>
#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. */
h = CreateFileA ("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, &sec_none_nih,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE || h == 0)
{
char *buf;
buf = (char *) alloca (100 + strlen (failedexpr));
__small_sprintf (buf, "Failed assertion\n\t%s\nat line %d of file %s",
failedexpr, line, file);
MessageBox (NULL, buf, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
}
else
{
CloseHandle (h);
small_printf ("assertion \"%s\" failed: file \"%s\", line %d\n",
failedexpr, file, line);
}
abort ();
/* NOTREACHED */
}