aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Robinson <andr345@gmail.com>2009-05-09 12:43:11 +0200
committerAndreas Robinson <andr345@gmail.com>2009-05-12 12:55:40 +0200
commit2f776f6b60ab2b2d8b8cbb061821113dbefe4aae (patch)
tree13abef8e74051d4a45b31443103c0434163d3151
parent17dbb9629fbad70de2626b663fcf21f6bc2517c8 (diff)
downloadmodule-init-tools-2f776f6b60ab2b2d8b8cbb061821113dbefe4aae.tar.gz
util: introduce new string table object
load_symbols() and calculate_deps() in moduleops call functions in depmod as a way of passing multiple symbols back to depmod. This adds a string table to replace those callbacks. Signed-off-by: Andreas Robinson <andr345@gmail.com>
-rw-r--r--util.c33
-rw-r--r--util.h9
2 files changed, 42 insertions, 0 deletions
diff --git a/util.c b/util.c
index 482363b..d3342df 100644
--- a/util.c
+++ b/util.c
@@ -114,6 +114,39 @@ char *underscores(char *string)
}
/*
+ * strtbl_add - add a string to a string table.
+ *
+ * @str: string to add
+ * @tbl: current string table. NULL = allocate new table
+ *
+ * Allocates an array of pointers to strings.
+ * The strings themselves are not actually kept in the table.
+ *
+ * Returns reallocated and updated string table. NULL = out of memory.
+ */
+struct string_table *strtbl_add(const char *str, struct string_table *tbl)
+{
+ if (tbl == NULL) {
+ const char max = 100;
+ tbl = malloc(sizeof(*tbl) + sizeof(char *) * max);
+ if (!tbl)
+ return NULL;
+ tbl->max = max;
+ tbl->cnt = 0;
+ }
+ if (tbl->cnt >= tbl->max) {
+ tbl->max *= 2;
+ tbl = realloc(tbl, sizeof(*tbl) + sizeof(char *) * tbl->max);
+ if (!tbl)
+ return NULL;
+ }
+ tbl->str[tbl->cnt] = str;
+ tbl->cnt += 1;
+
+ return tbl;
+}
+
+/*
* Get the basename in a pathname.
* Unlike the standard implementation, this does not copy the string.
*/
diff --git a/util.h b/util.h
index fbda299..7eef1d6 100644
--- a/util.h
+++ b/util.h
@@ -3,12 +3,21 @@
#include <stdio.h>
+struct string_table
+{
+ unsigned int cnt;
+ unsigned int max;
+ const char *str[0];
+};
+
char *getline_wrapped(FILE *file, unsigned int *linenum);
void filename2modname(char *modname, const char *filename);
char *underscores(char *string);
char *my_basename(const char *path);
+struct string_table *strtbl_add(const char *str, struct string_table *tbl);
+
const char *next_string(const char *string, unsigned long *secsize);
/*