#line 54 "heap.c-nw" #include #include #ifndef BSD #include #else #include #endif #include #include #ifdef __export #define FILE / ## *"*/__FI ## LE__/*"* ## / #define LINE / ## *"*/__LI ## NE__/*"* ## / #endif #define fatal(msg) fatal3(msg, FILE, LINE) #define new(p) if (((p)=malloc(sizeof(*(p))))); else fatal("out of memory") #define dispose(p) if (!(p)) ; else (free(p), (p) = (void*)0) #define heapmax(p) 9999999 /* ? */ #define newstring(s) heap_newstring(s, -1, FILE, LINE) #define newnstring(s,n) heap_newstring(s, n, FILE, LINE) #define newarray(p,n) \ if (((p)=malloc((n)*sizeof(*(p))))); else fatal("out of memory") #define renewarray(p,n) \ if (((p)=realloc(p,(n)*sizeof(*(p))))); else fatal("out of memory") EXPORTDEF(fatal(msg)) EXPORTDEF(new(p)) EXPORTDEF(dispose(p)) EXPORTDEF(heapmax(p)) EXPORTDEF(newstring(s)) EXPORTDEF(newnstring(s,n)) EXPORTDEF(newarray(p,n)) EXPORTDEF(renewarray(p,n)) EXPORT void fatal3(const char *s, const char *file, const int line) { fprintf(stderr, "%s (file %s, line %d)\n", s, file, line); abort(); } EXPORT char * heap_newstring(const char *s, int n, const char *file, int line) { char *t; if (n < 0) n = strlen(s); if (!s) return NULL; t = malloc((n + 1) * sizeof(*t)); if (!t) fatal3("out of memory", file, line); strncpy(t, s, n); t[n] = '\0'; return t; }