home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_10
/
1010050a
< prev
next >
Wrap
Text File
|
1992-08-12
|
1KB
|
47 lines
/* Listing 3
Defines macros for accessing test versions of
calloc and malloc and for collecting and reporting
errors.
*/
#if defined( TEST )
#include <stddef.h>
/* macro to print error message */
#define ErrorMsg(testNumber,msg) \
(fprintf(stderr,"\n\t\a%d)%s",testNumber,msg),\
++errors)
/* macro to initialize error counter and display
start message*/
#define StartTest(list) \
int errors = 0; \
fprintf(stderr,"\nTesting %s...\n",list)
/* macro to report results */
#define EndTest \
{ \
if(errors) \
fprintf(stderr, \
"\n%d errors detected\n"); \
else \
fprintf(stderr,"Success\n"); \
return errors; \
}
/* re-direct calloc and malloc to test versions */
#define calloc(x,y) testCalloc(x,y)
#define malloc(x) testMalloc(x)
/* prototype calloc and malloc shell functions */
void *testCalloc( size_t numElems,
size_t elemSize );
void *testMalloc( size_t numElems );
/* prototypes to set the number of times calloc
and malloc will work before failing */
void SetCalloc( int passes );
void SetMalloc( int passes );
#endif