1 /*- FUNCS.C ----------------------------------------------------------------*/
2 /*- terminate the program reporting an error -------------------------------*/
3
4 #include "structs.h"
5 #include "bsp.h"
6
7 #ifdef HAVE_UNISTD_H
8 # include <unistd.h>
9 #endif
10
ProgError(const char * errstr,...)11 void ProgError(const char *errstr, ...)
12 {
13 va_list args;
14
15 va_start( args, errstr);
16 fprintf(stderr, "\nProgram Error: *** ");
17 vfprintf( stderr, errstr, args);
18 fprintf(stderr, " ***\n");
19 va_end( args);
20 #ifdef HAVE_UNLINK
21 if (unlinkwad) unlink(unlinkwad);
22 #endif
23 exit( 5);
24 }
25
26 /* Print stuff if verbose output */
27
28 int verbosity;
29
Verbose(const char * errstr,...)30 void Verbose(const char *errstr, ...)
31 {
32 va_list args;
33
34 if (!verbosity) return;
35
36 va_start( args, errstr);
37 vprintf(errstr, args);
38 va_end( args);
39 }
40
41 #ifndef WITH_DMALLOC
42 /*- allocate memory with error checking ------------------------------------*/
GetMemory(size_t size)43 void* GetMemory(size_t size)
44 {
45 void *ret = malloc( size);
46 if (!ret)
47 ProgError( "out of memory (cannot allocate %zu bytes)", size);
48 return ret;
49 }
50
51 /*- reallocate memory with error checking ----------------------------------*/
52
ResizeMemory(void * old,size_t size)53 void* ResizeMemory(void *old, size_t size)
54 {
55 void *ret = realloc( old, size);
56 if (!ret)
57 ProgError( "out of memory (cannot reallocate %zu bytes)", size);
58 return ret;
59 }
60
61 #endif
62 /*--------------------------------------------------------------------------*/
63
64