6 cerr = malloc_chk(sizeof(CERR), "cerr");
17 bool addcerrlist(int newerrc, CERR newerrv[])
22 assert(newerrc > 0 && newerrv != NULL);
23 if(cerrlist == NULL) {
24 p = cerrlist = malloc_chk(sizeof(CERRLIST), "cerrlist");
26 for(p = cerrlist; p != NULL; p = p->next) {
29 p = q->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
31 for(i = 0; i < newerrc; i++) {
32 p->cerr = &(newerrv[i]);
33 p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
42 void setcerr(int num, const char *str)
47 cerr->msg = malloc_chk(CERRMSGSIZE + 1, "cerr.msg");
48 if(str != NULL && strlen(str) <= CERRSTRSIZE) {
49 sprintf(cerr->msg, "%s: %s", str, getcerrmsg(cerr->num));
51 strcpy(cerr->msg, getcerrmsg(cerr->num));
55 /* エラーリストから、エラー番号に対応するメッセージを返す */
56 char *getcerrmsg(int num)
60 for(p = cerrlist; p != NULL; p = p->next) {
61 if(num == p->cerr->num) {
65 return "unknown error";
68 /* エラーリストと現在のエラーを解放する */
71 CERRLIST *p = cerrlist, *q;
76 free_chk(p, "freecerr.p");
80 free_chk(cerr->msg, "cerr.msg");
82 free_chk(cerr, "cerr");