Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / tests / checks.c
1 /****************************************************************************
2 *
3 *                   SciTech OS Portability Manager Library
4 *
5 *  ========================================================================
6 *
7 *    The contents of this file are subject to the SciTech MGL Public
8 *    License Version 1.0 (the "License"); you may not use this file
9 *    except in compliance with the License. You may obtain a copy of
10 *    the License at http://www.scitechsoft.com/mgl-license.txt
11 *
12 *    Software distributed under the License is distributed on an
13 *    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 *    implied. See the License for the specific language governing
15 *    rights and limitations under the License.
16 *
17 *    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 *
19 *    The Initial Developer of the Original Code is SciTech Software, Inc.
20 *    All Rights Reserved.
21 *
22 *  ========================================================================
23 *
24 * Language:     ANSI C
25 * Environment:  Any
26 *
27 * Description:  Main module for building checked builds of products with
28 *               assertions and trace code.
29 *
30 ****************************************************************************/
31
32 #include "scitech.h"
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #ifdef  __WINDOWS__
37 #define WIN32_LEAN_AND_MEAN
38 #define STRICT
39 #include <windows.h>
40 #endif
41
42 #ifdef  CHECKED
43
44 /*---------------------------- Global variables ---------------------------*/
45
46 #define LOGFILE "\\scitech.log"
47
48 void (*_CHK_fail)(int fatal,const char *msg,const char *cond,const char *file,int line) = _CHK_defaultFail;
49
50 /*---------------------------- Implementation -----------------------------*/
51
52 /****************************************************************************
53 DESCRIPTION:
54 Handles fatal error and warning conditions for checked builds.
55
56 HEADER:
57 scitech.h
58
59 REMARKS:
60 This function is called whenever an inline check or warning fails in any
61 of the SciTech runtime libraries. Warning conditions simply cause the
62 condition to be logged to the log file and send to the system debugger
63 under Window. Fatal error conditions do all of the above, and then
64 terminate the program with a fatal error conditions.
65
66 This handler may be overriden by the user code if necessary to replace it
67 with a different handler (the MGL for instance overrides this and replaces
68 it with a handler that does an MGL_exit() before terminating the application
69 so that it will clean up correctly.
70 ****************************************************************************/
71 void _CHK_defaultFail(
72     int fatal,
73     const char *msg,
74     const char *cond,
75     const char *file,
76     int line)
77 {
78     char    buf[256];
79     FILE    *log = fopen(LOGFILE, "at+");
80
81     sprintf(buf,msg,cond,file,line);
82     if (log) {
83         fputs(buf,log);
84         fflush(log);
85         fclose(log);
86 #ifdef  __WINDOWS__
87         OutputDebugStr(buf);
88 #endif
89         }
90     if (fatal) {
91 #ifdef  __WINDOWS__
92         MessageBox(NULL, buf,"Fatal Error!",MB_ICONEXCLAMATION);
93 #else
94         fputs(buf,stderr);
95 #endif
96         exit(-1);
97         }
98 }
99
100 #endif  /* CHECKED */