comparison src/generic.c @ 43:f6db1f060a95

start on outlook 2003 64 bit format
author carl
date Sun, 06 Jan 2008 14:47:06 -0800
parents
children
comparison
equal deleted inserted replaced
42:7a97f50c39c5 43:f6db1f060a95
1
2
3 #include <ctype.h>
4 #include <errno.h>
5 #include <malloc.h>
6 #include <signal.h>
7 #include <stdarg.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "generic.h"
12
13 #ifdef WITH_DMALLOC
14 #include <dmalloc.h>
15 #endif
16
17
18
19
20 void pDIE( char *fmt, ... )
21 {
22 va_list ap;
23 va_start( ap, fmt );
24 //fprintf( stderr, "Fatal error (will segfault): ");
25 vfprintf( stderr, fmt, ap );
26 fprintf( stderr, "\n" );
27 va_end(ap);
28 raise( SIGSEGV );
29 }
30
31 void pWARN( char *fmt, ... )
32 {
33 va_list ap;
34 va_start( ap, fmt );
35 fprintf( stderr, "WARNING: ");
36 vfprintf( stderr, fmt, ap );
37 fprintf( stderr, "\n" );
38 va_end(ap);
39 }
40
41 void *F_MALLOC( size_t size )
42 {
43 void *result;
44
45 result = malloc( size );
46 ASSERT( NULL != result, "malloc() failure." );
47
48 return result;
49 }
50
51 void *F_REALLOC( void *p, size_t size )
52 {
53 void *result;
54
55 //if( NULL != p ) hexdump((char*)p - 128, 0, 128, 1 );
56 if(!p) {
57 ASSERT( NULL != ( result = malloc( size ) ), "malloc() failure." );
58 }
59 else {
60 ASSERT( NULL != ( result = realloc( p, size ) ), "realloc() failure." );
61 }
62
63 //hexdump((char*)result - 128, 0, 128, 1 );
64 fflush(stderr);
65 return result;
66 }
67
68
69
70 int DEBUG_LEVEL = DB_INFO;
71
72 void db_default( char *file, int line, int level, char *fmt, ... )
73 {
74 va_list ap;
75 if( level <= DEBUG_LEVEL ) {
76 switch( level ) {
77 case DB_CRASH:
78 fprintf(stderr, "CRASH");
79 break;
80 case DB_ERR:
81 fprintf(stderr, "ERROR");
82 break;
83 case DB_WARN:
84 fprintf(stderr, "WARNING");
85 break;
86 case DB_INFO:
87 case DB_VERB:
88 break;
89 default:
90 fprintf(stderr, "DEBUG(%d)", level );
91 }
92
93 if( level <= DB_WARN )
94 fprintf(stderr, " (%s:%d)", file, line );
95
96 if( DB_INFO != level && DB_VERB != level )
97 fprintf(stderr, ": ");
98
99 va_start( ap, fmt );
100 vfprintf(stderr, fmt, ap );
101 fprintf(stderr, "\n" );
102 va_end( ap );
103 }
104 }
105
106 void (*dbfunc)(char *file, int line, int level, char *fmt, ...) = &db_default;
107
108
109
110