10 cerr = malloc_chk(sizeof(CERR), "cerr");
16 CERRLIST *cerrlist = NULL;
18 void addcerrlist(int cerrc, CERR cerrv[])
21 CERRLIST *p = NULL, *q = malloc_chk(sizeof(CERRLIST), "cerrlist");
23 assert(cerrc > 0 && cerrv != NULL);
24 for(i = 0; i < cerrc; i++) {
28 p = p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
41 if(cerrlist == NULL) {
42 puts("error list is null.");
44 for(p = cerrlist; p != NULL; p = p->next) {
45 printf("%d: %s\n", p->cerr->num, p->cerr->msg);
50 void setcerr(int num, const char *str)
55 cerr->msg = malloc_chk(CERRMSGSIZE + 1, "cerr.msg");
56 if(0 < strlen(str) && strlen(str) <= CERRSTRSIZE) {
57 sprintf(cerr->msg, "%s: %s", str, getcerrmsg(cerr->num));
59 strcpy(cerr->msg, getcerrmsg(cerr->num));
63 char *getcerrmsg(int num)
66 char *msg = "unknown error";
68 for(p = cerrlist; p != NULL; p = p->next) {
69 if(num == p->cerr->num) {
79 CERRLIST *p = cerrlist, *q;
86 for(p = cerrlist; p != NULL; p = q) {