diff --git a/lib/com_err/com_right.h b/lib/com_err/com_right.h index 46aec001a..e13855aba 100644 --- a/lib/com_err/com_right.h +++ b/lib/com_err/com_right.h @@ -52,6 +52,7 @@ struct et_list { extern struct et_list *_et_list; const char *com_right (struct et_list *list, long code); +const char *com_right_r (struct et_list *list, long code, char *, size_t); void initialize_error_table_r (struct et_list **, const char **, int, long); void free_error_table (struct et_list *); diff --git a/lib/com_err/error.c b/lib/com_err/error.c index 6b12c00c7..d4a42ac5d 100644 --- a/lib/com_err/error.c +++ b/lib/com_err/error.c @@ -47,18 +47,28 @@ const char * com_right(struct et_list *list, long code) +{ + struct et_list *p; + for (p = list; p; p = p->next) + if (code >= p->table->base && code < p->table->base + p->table->n_msgs) + return p->table->msgs[code - p->table->base]; + return NULL; +} + +const char * +com_right_r(struct et_list *list, long code, char *str, size_t len) { struct et_list *p; for (p = list; p; p = p->next) { if (code >= p->table->base && code < p->table->base + p->table->n_msgs) { - const char *str = p->table->msgs[code - p->table->base]; + const char *msg = p->table->msgs[code - p->table->base]; #ifdef LIBINTL char domain[12 + 20]; snprintf(domain, sizeof(domain), "heim_com_err%d", p->table->base); #endif - return dgettext(domain, str); + strlcpy(str, dgettext(domain, msg), len); + return str; } - } return NULL; } diff --git a/lib/com_err/version-script.map b/lib/com_err/version-script.map index dd9a2adba..8da2fef6d 100644 --- a/lib/com_err/version-script.map +++ b/lib/com_err/version-script.map @@ -3,6 +3,7 @@ HEIMDAL_COM_ERR_1.0 { global: com_right; + com_right_r; free_error_table; initialize_error_table_r; add_to_error_table;