5 cerr = malloc_chk(sizeof(CERR), "cerr");
11 CERRLIST *cerrlist = NULL;
13 void addcerrlist(int cerrc, CERR cerrv[])
15 CERRLIST *stat = NULL;
18 assert(cerrc > 0 && cerrv != NULL);
19 for(int i = 0; i < cerrc; i++) {
21 stat = p = malloc_chk(sizeof(CERRLIST), "cerrlist");
23 p = p->next = malloc_chk(sizeof(CERRLIST), "cerrlist->next");
36 if(cerrlist == NULL) {
37 puts("error list is null.");
39 for(p = cerrlist; p != NULL; p = p->next) {
40 printf("%d: %s\n", p->cerr->num, p->cerr->msg);
45 void setcerr(int num, const char *str)
50 cerr->msg = malloc_chk(CERRMSGSIZE + 1, "cerr.msg");
51 if(0 < strlen(str) && strlen(str) <= CERRSTRSIZE) {
52 sprintf(cerr->msg, "%s: %s", str, getcerrmsg(cerr->num));
54 strcpy(cerr->msg, getcerrmsg(cerr->num));
58 char *getcerrmsg(int num)
61 char *msg = "unknown error";
63 for(p = cerrlist; p != NULL; p = p->next) {
64 if(num == p->cerr->num) {
82 for(p = cerrlist; p != NULL; p = q) {