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]);
46 p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
57 void setcerr(int num, const char *str)
62 cerr->msg = malloc_chk(CERRMSGSIZE + 1, "cerr.msg");
63 if(str != NULL && strlen(str) <= CERRSTRSIZE) {
64 sprintf(cerr->msg, "%s: %s", str, getcerrmsg(cerr->num));
66 strcpy(cerr->msg, getcerrmsg(cerr->num));
71 * エラーリストから、エラー番号に対応するメッセージを返す
73 char *getcerrmsg(int num)
77 for(p = cerrlist; p != NULL; p = p->next) {
78 if(num == p->cerr->num) {
82 return "unknown error";
90 CERRLIST *p = cerrlist, *q;
95 free_chk(p, "freecerr.p");
99 free_chk(cerr->msg, "cerr.msg");
101 free_chk(cerr, "cerr");