diff options
author | Andreas Robinson <andr345@gmail.com> | 2009-05-09 12:43:11 +0200 |
---|---|---|
committer | Andreas Robinson <andr345@gmail.com> | 2009-05-12 12:55:40 +0200 |
commit | 2f776f6b60ab2b2d8b8cbb061821113dbefe4aae (patch) | |
tree | 13abef8e74051d4a45b31443103c0434163d3151 | |
parent | 17dbb9629fbad70de2626b663fcf21f6bc2517c8 (diff) | |
download | module-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.c | 33 | ||||
-rw-r--r-- | util.h | 9 |
2 files changed, 42 insertions, 0 deletions
@@ -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. */ @@ -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); /* |