Whamcloud - gitweb
libcom_err: Add support for Heimdal com_right_r function()
authorTheodore Ts'o <tytso@mit.edu>
Sun, 14 Mar 2010 23:34:53 +0000 (19:34 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 15 Mar 2010 04:14:12 +0000 (00:14 -0400)
Addresses-Sourceforge-Bug: #2963865
Addresses-Debian-Bug: #558910

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/et/com_err.h
lib/et/com_right.c

index de0146e..eb2106f 100644 (file)
@@ -16,6 +16,7 @@
 #define COM_ERR_ATTR(x)
 #endif
 
+#include <stddef.h>
 #include <stdarg.h>
 
 typedef long errcode_t;
@@ -49,6 +50,7 @@ extern void add_to_error_table(struct et_list *new_table);
 
 /* Provided for Heimdall compatibility */
 extern const char *com_right(struct et_list *list, long code);
+extern const char *com_right_r(struct et_list *list, long code, char *str, size_t len);
 extern void initialize_error_table_r(struct et_list **list,
                                     const char **messages,
                                     int num_errors,
index 173fd1a..f00e910 100644 (file)
@@ -55,6 +55,21 @@ com_right(struct et_list *list, long code)
     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)) {
+            strncpy(str, p->table->msgs[code - p->table->base], len);
+            str[len-1] = '\0';
+            return str;
+        }
+    }
+    return NULL;
+}
+
 struct foobar {
     struct et_list etl;
     struct error_table tab;