13 cerr = malloc_chk(sizeof(CERR), "cerr");
30 bool addcerrlist(int newerrc, CERR newerrv[])
35 assert(newerrc > 0 && newerrv != NULL);
36 if(cerrlist == NULL) {
37 p = cerrlist = malloc_chk(sizeof(CERRLIST), "cerrlist");
39 for(p = cerrlist; p != NULL; p = p->next) {
42 p = q->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
44 for(i = 0; i < newerrc; i++) {
45 p->cerr = &newerrv[i];
47 p = p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
60 if(cerrlist == NULL) {
61 puts("error list is null.");
63 for(p = cerrlist; p != NULL; p = p->next) {
64 printf("%d: %s\n", p->cerr->num, p->cerr->msg);
72 void setcerr(int num, const char *str)
77 cerr->msg = malloc_chk(CERRMSGSIZE + 1, "cerr.msg");
78 if(str != NULL && strlen(str) <= CERRSTRSIZE) {
79 sprintf(cerr->msg, "%s: %s", str, getcerrmsg(cerr->num));
81 strcpy(cerr->msg, getcerrmsg(cerr->num));
86 * エラーリストから、エラー番号に対応するメッセージを返す
88 char *getcerrmsg(int num)
91 char *msg = "unknown error";
93 for(p = cerrlist; p != NULL; p = p->next) {
94 if(num == p->cerr->num) {
107 CERRLIST *p = cerrlist, *q;
110 free_chk(cerr->msg, "cerr.msg");
112 free_chk(cerr, "cerr");
114 for(p = cerrlist; p != NULL; p = q) {
116 free_chk(p, "freecerr.p");