/* * utils.h: header file for utils.c, various useful macros * * Author: John DiMarco, University of Toronto, CDF * jdd@cdf.toronto.edu * * $Id: utils.h,v 1.4 1995/08/12 19:32:43 jdd Exp $ */ /* new - mallocs any sized type */ #ifndef lint #define new(t) (t *)mylib_malloc(sizeof(t),__FILE__,__LINE__) #else #define new(t) (t *)NULL #endif /* mem - mallocs a given number of bytes */ #define mem(l) mylib_malloc((unsigned)l,__FILE__,__LINE__) /* rmem - reallocs a given number of bytes */ #define rmem(c,l) mylib_realloc(c,(unsigned)l,__FILE__,__LINE__) /* s - returns a copy of a given string */ #define s(c) mylib_scopy(c,__FILE__,__LINE__) /* rs - returns a copy of the second string in place of the first string, using realloc */ #define rs(c,d) mylib_srcopy(c,strlen(d),__FILE__,__LINE__) /* assert - error message if statement is false */ #ifdef DEBUG #define assert(c) if(!(c))(void)fprintf(stderr,"%s: %d: Assert false\n",__FILE__,__LINE__) #else #define assert(c) 0 #endif /* STREQ - indicate whether two strings are equal */ #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) #define loop for(;;) #define NUL(x) (x)NULL #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define YES 1 #define NO 0 /* Error - print like fprintf(stderr, ...) and die. Progname included at beginning of message, newline at end. */ extern void Error(char *, ...); /* Warning - like error, without dying */ extern void Warning(char *, ...); extern char *mylib_malloc(); extern char *mylib_realloc(); extern char *mylib_scopy(); extern char *mylib_srcopy(); extern char *cat(char *, ...); extern char *getstr(); extern FILE *efopen(); extern void efclose(); extern void dfprintf(int, FILE *, char *, ...); extern char *progname; /* application's name. Used by Error, Warning. */ extern int d; /* debug level */ #define PORT_ANY 0 #define getkvm(k,a,b,l) if(0>kvm_read((k),(a),(b),(l))) \ Error("getkvm: kvm_read(%08x, %d)",(a),(l));