ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

assert.c
Go to the documentation of this file.
00001 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
00002 #include <precomp.h>
00003 #include <assert.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <signal.h>
00007 
00008 static const char formatstr[] =
00009     "Assertion failed!\n\n"
00010     "Program: %s\n"
00011     "File: %s\n"
00012     "Line: %ld\n\n"
00013     "Expression: %s\n"
00014     "Press Retry to debug the application\n";
00015 
00016 
00017 /*
00018  * @implemented
00019  */
00020 void _assert(const char *exp, const char *file, unsigned line)
00021 {
00022     int (WINAPI *pMessageBoxA)(HWND, LPCTSTR, LPCTSTR, UINT);
00023     HMODULE hmodUser32;
00024     char achProgram[40];
00025     char *pszBuffer;
00026     size_t len;
00027     int iResult;
00028 
00029     /* Assertion failed at foo.c line 45: x<y */
00030     fprintf(stderr, "Assertion failed at %s line %d: %s\n", file, line, exp);
00031     FIXME("Assertion failed at %s line %d: %s\n", file, line, exp);
00032 
00033     /* Get MessageBoxA function pointer */
00034     hmodUser32 = LoadLibrary("user32.dll");
00035     pMessageBoxA = (PVOID)GetProcAddress(hmodUser32, "MessageBoxA");
00036     if (!pMessageBoxA)
00037     {
00038         abort();
00039     }
00040 
00041     /* Get the file name of the module */
00042     len = GetModuleFileNameA(NULL, achProgram, 40);
00043 
00044     /* Calculate full length of the message */
00045     len += sizeof(formatstr) + len + strlen(exp) + strlen(file);
00046 
00047     /* Allocate a buffer */
00048     pszBuffer = malloc(len + 1);
00049 
00050     /* Format a message */
00051     _snprintf(pszBuffer, len, formatstr, achProgram, file, line, exp);
00052 
00053     /* Display a message box */
00054     iResult = pMessageBoxA(NULL,
00055                           pszBuffer,
00056                           "ReactOS C Runtime Library",
00057                           MB_ABORTRETRYIGNORE | MB_ICONERROR);
00058 
00059     free(pszBuffer);
00060 
00061     /* Does the user want to abort? */
00062     if (iResult == IDABORT)
00063     {
00064         abort();
00065     }
00066 
00067     /* Does the user want to debug? */
00068     if (iResult == IDRETRY)
00069     {
00070         DbgRaiseAssertionFailure();
00071     }
00072 }

Generated on Sun May 27 2012 04:36:21 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.