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");
61 if(cerrlist == NULL) {
62 puts("error list is null.");
64 for(p = cerrlist; p != NULL; p = p->next) {
65 printf("%d: %s\n", p->cerr->num, p->cerr->msg);
73 void setcerr(int num, const char *str)
78 cerr->msg = malloc_chk(CERRMSGSIZE + 1, "cerr.msg");
79 if(str != NULL && strlen(str) <= CERRSTRSIZE) {
80 sprintf(cerr->msg, "%s: %s", str, getcerrmsg(cerr->num));
82 strcpy(cerr->msg, getcerrmsg(cerr->num));
87 * エラーリストから、エラー番号に対応するメッセージを返す
89 char *getcerrmsg(int num)
93 for(p = cerrlist; p != NULL; p = p->next) {
94 if(num == p->cerr->num) {
98 return "unknown error";
106 CERRLIST *p = cerrlist, *q;
111 free_chk(p, "freecerr.p");
115 /* free_chk(cerr->msg, "cerr->msg"); */
117 free_chk(cerr, "cerr");