2005-06-20 Theodore Ts'o <tytso@mit.edu>
+ * error_message.c, init_et.c: Segregate error tables registered
+ via add_error_table() and the other dynamic methods from
+ the ones allocated via initialize_xxx_error_table() so
+ that we won't fail even for error tables created using old
+ versions of compile_et. Thanks to Nalin Dahyabhai for
+ this suggested patch.
+
* et_c.awk: Use a dynamically allocated structure in
initialize_xxx_error_table(), to prevent segfaults if an
old library calls initialize_xxx_error_table, and another
static char buffer[25];
struct et_list * _et_list = (struct et_list *) NULL;
+struct et_list * _et_dynamic_list = (struct et_list *) NULL;
const char * error_message (errcode_t code)
return(et->table->msgs[offset]);
}
}
+ for (et = _et_dynamic_list; et; et = et->next) {
+ if (et->table->base == table_num) {
+ /* This is the right table */
+ if (et->table->n_msgs <= offset)
+ goto oops;
+ return(et->table->msgs[offset]);
+ }
+ }
oops:
strcpy (buffer, "Unknown code ");
if (table_num) {
*/
errcode_t add_error_table(const struct error_table * et)
{
- struct et_list *el = _et_list;
-
- while (el) {
- if (el->table->base == et->base)
- return EEXIST;
- el = el->next;
- }
+ struct et_list *el;
if (!(el = (struct et_list *) malloc(sizeof(struct et_list))))
return ENOMEM;
el->table = et;
- el->next = _et_list;
- _et_list = el;
+ el->next = _et_dynamic_list;
+ _et_dynamic_list = el;
return 0;
}
*/
errcode_t remove_error_table(const struct error_table * et)
{
- struct et_list *el = _et_list;
+ struct et_list *el = _et_dynamic_list;
struct et_list *el2 = 0;
while (el) {
if (el2) /* Not the beginning of the list */
el2->next = el->next;
else
- _et_list = el->next;
+ _et_dynamic_list = el->next;
(void) free(el);
return 0;
}
struct error_table et;
};
-extern struct et_list * _et_list;
+extern struct et_list * _et_dynamic_list;
int init_error_table(const char * const *msgs, long base, int count)
{
new_et->et.base = base;
new_et->et.n_msgs= count;
- new_et->etl.next = _et_list;
- _et_list = &new_et->etl;
+ new_et->etl.next = _et_dynamic_list;
+ _et_dynamic_list = &new_et->etl;
return 0;
}