ReactOS 0.4.16-dev-257-g6aa11ac
assert.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS C runtime library
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: lib/sdk/crt/misc/assert.c
5 * PURPOSE: _assert implementation
6 * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
7 */
8
9#include <precomp.h>
10
11static const char formatstr[] =
12 "Assertion failed!\n\n"
13 "Program: %s\n"
14 "File: %s\n"
15 "Line: %ld\n\n"
16 "Expression: %s\n"
17 "Press Retry to debug the application\n\0";
18
19void
21 const char *exp,
22 const char *file,
23 unsigned line)
24{
25 char achProgram[MAX_PATH];
26 char *pszBuffer;
27 size_t len;
28 int iResult;
29
30 /* First common debug message */
31 FIXME("Assertion failed: %s, file %s, line %d\n", exp, file, line);
32
33 /* Check if output should go to stderr */
36 {
37 /* Print 'Assertion failed: x<y, file foo.c, line 45' to stderr */
38 fprintf(stderr, "Assertion failed: %s, file %s, line %u\n", exp, file, line);
39 abort();
40 }
41
42 /* Get the file name of the module */
43 len = GetModuleFileNameA(NULL, achProgram, sizeof(achProgram));
44
45 /* Calculate full length of the message */
46 len += sizeof(formatstr) + len + strlen(exp) + strlen(file);
47
48 /* Allocate a buffer */
49 pszBuffer = malloc(len + 1);
50
51 /* Format a message */
52 _snprintf(pszBuffer, len, formatstr, achProgram, file, line, exp);
53
54 /* Display a message box */
56
57 /* Free the buffer */
58 free(pszBuffer);
59
60 /* Does the user want to ignore? */
61 if (iResult == IDIGNORE)
62 {
63 /* Just return to the caller */
64 return;
65 }
66
67 /* Does the user want to debug? */
68 if (iResult == IDRETRY)
69 {
70 /* Break and return to the caller */
72 return;
73 }
74
75 /* Reset all abort flags (we don*t want another message box) and abort */
76 _set_abort_behavior(0, 0xffffffff);
77 abort();
78}
79
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define FIXME(fmt,...)
Definition: precomp.h:53
void _assert(const char *exp, const char *file, unsigned line)
Definition: assert.c:20
static const char formatstr[]
Definition: assert.c:11
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
GLenum GLsizei len
Definition: glext.h:6722
#define abort()
Definition: i386-dis.c:34
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_CRTIMP unsigned int __cdecl _set_abort_behavior(_In_ unsigned int _Flags, _In_ unsigned int _Mask)
#define _OUT_TO_DEFAULT
Definition: stdlib.h:110
#define _OUT_TO_STDERR
Definition: stdlib.h:111
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
DWORD exp
Definition: msg.c:16058
#define _CONSOLE_APP
Definition: internal.h:145
int __cdecl __crt_MessageBoxA(_In_opt_ const char *pszText, _In_ unsigned int uType)
int msvcrt_error_mode
Definition: errno.c:113
int __app_type
Definition: environ.c:30
Definition: fci.c:127
Definition: parser.c:49
#define IDIGNORE
Definition: winuser.h:837
#define MB_ICONERROR
Definition: winuser.h:790
#define MB_ABORTRETRYIGNORE
Definition: winuser.h:794
#define IDRETRY
Definition: winuser.h:836
#define _snprintf
Definition: xmlstorage.h:200