6 * Copyright 1987 by the Student Information Processing Board
7 * of the Massachusetts Institute of Technology
9 * Permission to use, copy, modify, and distribute this software and
10 * its documentation for any purpose is hereby granted, provided that
11 * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
12 * advertising or publicity pertaining to distribution of the software
13 * without specific, written prior permission. M.I.T. and the
14 * M.I.T. S.I.P.B. make no representations about the suitability of
15 * this software for any purpose. It is provided "as is" without
16 * express or implied warranty.
24 #include "error_table.h"
27 static char buffer[25];
29 struct et_list * _et_list = (struct et_list *) NULL;
30 struct et_list * _et_dynamic_list = (struct et_list *) NULL;
33 const char * error_message (errcode_t code)
41 offset = (int) (code & ((1<<ERRCODE_RANGE)-1));
42 table_num = code - offset;
44 #ifdef HAS_SYS_ERRLIST
45 if (offset < sys_nerr)
46 return(sys_errlist[offset]);
50 cp = strerror(offset);
57 for (et = _et_list; et; et = et->next) {
58 if (et->table->base == table_num) {
59 /* This is the right table */
60 if (et->table->n_msgs <= offset)
62 return(et->table->msgs[offset]);
65 for (et = _et_dynamic_list; et; et = et->next) {
66 if (et->table->base == table_num) {
67 /* This is the right table */
68 if (et->table->n_msgs <= offset)
70 return(et->table->msgs[offset]);
74 strcpy (buffer, "Unknown code ");
76 strcat (buffer, error_table_name (table_num));
79 for (cp = buffer; *cp; cp++)
82 *cp++ = '0' + offset / 100;
86 if (started || offset >= 10) {
87 *cp++ = '0' + offset / 10;
96 * New interface provided by krb5's com_err library
98 errcode_t add_error_table(const struct error_table * et)
102 if (!(el = (struct et_list *) malloc(sizeof(struct et_list))))
106 el->next = _et_dynamic_list;
107 _et_dynamic_list = el;
113 * New interface provided by krb5's com_err library
115 errcode_t remove_error_table(const struct error_table * et)
117 struct et_list *el = _et_dynamic_list;
118 struct et_list *el2 = 0;
121 if (el->table->base == et->base) {
122 if (el2) /* Not the beginning of the list */
123 el2->next = el->next;
125 _et_dynamic_list = el->next;
136 * Variant of the interface provided by Heimdal's com_err library
139 add_to_error_table(struct et_list *new_table)
141 add_error_table(new_table->table);