• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the mingw-w64 runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 
7 #include <assert.h>
8 #include <stdlib.h>
9 #include <windows.h>
10 #include "msvcrt.h"
11 
12 /* _wassert is not available on XP, so forward it to _assert if needed */
mingw_wassert(const wchar_t * _Message,const wchar_t * _File,unsigned _Line)13 static void __cdecl mingw_wassert(const wchar_t *_Message, const wchar_t *_File, unsigned _Line)
14 {
15     char *message = NULL, *file = NULL;
16     size_t len;
17 
18     if ((len = wcstombs(NULL, _Message, 0)) != (size_t)-1)
19     {
20         message = malloc(len + 1);
21         wcstombs(message, _Message, len + 1);
22     }
23 
24     if ((len = wcstombs(NULL, _File, 0)) != (size_t)-1)
25     {
26         file = malloc(len + 1);
27         wcstombs(file, _File, len + 1);
28     }
29 
30     _assert(message, file, _Line);
31 
32     free(message);
33     free(file);
34 }
35 
36 static void __cdecl init_wassert(const wchar_t *message, const wchar_t *file, unsigned line);
37 
38 void (__cdecl *__MINGW_IMP_SYMBOL(_wassert))(const wchar_t*, const wchar_t*,unsigned) = init_wassert;
39 
init_wassert(const wchar_t * message,const wchar_t * file,unsigned line)40 static void __cdecl init_wassert(const wchar_t *message, const wchar_t *file, unsigned line)
41 {
42     void *func;
43 
44     func = (void*)GetProcAddress(__mingw_get_msvcrt_handle(), "_wassert");
45     if(!func)
46         func = mingw_wassert;
47 
48     return (__MINGW_IMP_SYMBOL(_wassert) = func)(message, file, line);
49 }
50