Changeset View
Changeset View
Standalone View
Standalone View
contrib/elftoolchain/libelftc/elftc_string_table.c
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | (st)->st_len = \ | ||||
((st)->st_len & \ | ((st)->st_len & \ | ||||
ELFTC_STRING_TABLE_COMPACTION_FLAG) | \ | ELFTC_STRING_TABLE_COMPACTION_FLAG) | \ | ||||
((len) << 1); \ | ((len) << 1); \ | ||||
} while (0) | } while (0) | ||||
struct _Elftc_String_Table { | struct _Elftc_String_Table { | ||||
unsigned int st_len; /* length and flags */ | unsigned int st_len; /* length and flags */ | ||||
int st_nbuckets; | int st_nbuckets; | ||||
int st_string_pool_size; | size_t st_string_pool_size; | ||||
char *st_string_pool; | char *st_string_pool; | ||||
SLIST_HEAD(_Elftc_String_Table_Bucket, | SLIST_HEAD(_Elftc_String_Table_Bucket, | ||||
_Elftc_String_Table_Entry) st_buckets[]; | _Elftc_String_Table_Entry) st_buckets[]; | ||||
}; | }; | ||||
static struct _Elftc_String_Table_Entry * | static struct _Elftc_String_Table_Entry * | ||||
elftc_string_table_find_hash_entry(Elftc_String_Table *st, const char *string, | elftc_string_table_find_hash_entry(Elftc_String_Table *st, const char *string, | ||||
int *rhashindex) | int *rhashindex) | ||||
Show All 19 Lines | elftc_string_table_find_hash_entry(Elftc_String_Table *st, const char *string, | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
static int | static int | ||||
elftc_string_table_add_to_pool(Elftc_String_Table *st, const char *string) | elftc_string_table_add_to_pool(Elftc_String_Table *st, const char *string) | ||||
{ | { | ||||
char *newpool; | char *newpool; | ||||
int len, newsize, stlen; | size_t len, newsize, stlen; | ||||
len = strlen(string) + 1; /* length, including the trailing NUL */ | len = strlen(string) + 1; /* length, including the trailing NUL */ | ||||
stlen = ELFTC_STRING_TABLE_LENGTH(st); | stlen = ELFTC_STRING_TABLE_LENGTH(st); | ||||
/* Resize the pool, if needed. */ | /* Resize the pool, if needed. */ | ||||
if (stlen + len >= st->st_string_pool_size) { | if (stlen + len >= st->st_string_pool_size) { | ||||
newsize = roundup(st->st_string_pool_size + | newsize = roundup(st->st_string_pool_size + | ||||
ELFTC_STRING_TABLE_POOL_SIZE_INCREMENT, | ELFTC_STRING_TABLE_POOL_SIZE_INCREMENT, | ||||
ELFTC_STRING_TABLE_POOL_SIZE_INCREMENT); | ELFTC_STRING_TABLE_POOL_SIZE_INCREMENT); | ||||
if ((newpool = realloc(st->st_string_pool, newsize)) == | if ((newpool = realloc(st->st_string_pool, newsize)) == | ||||
NULL) | NULL) | ||||
return (0); | return (0); | ||||
st->st_string_pool = newpool; | st->st_string_pool = newpool; | ||||
st->st_string_pool_size = newsize; | st->st_string_pool_size = newsize; | ||||
} | } | ||||
strcpy(st->st_string_pool + stlen, string); | strcpy(st->st_string_pool + stlen, string); | ||||
ELFTC_STRING_TABLE_UPDATE_LENGTH(st, stlen + len); | ELFTC_STRING_TABLE_UPDATE_LENGTH(st, stlen + len); | ||||
return (stlen); | return (stlen); | ||||
} | } | ||||
Elftc_String_Table * | Elftc_String_Table * | ||||
elftc_string_table_create(int sizehint) | elftc_string_table_create(size_t sizehint) | ||||
{ | { | ||||
int n, nbuckets, tablesize; | int n, nbuckets, tablesize; | ||||
struct _Elftc_String_Table *st; | struct _Elftc_String_Table *st; | ||||
if (sizehint < ELFTC_STRING_TABLE_DEFAULT_SIZE) | if (sizehint < ELFTC_STRING_TABLE_DEFAULT_SIZE) | ||||
sizehint = ELFTC_STRING_TABLE_DEFAULT_SIZE; | sizehint = ELFTC_STRING_TABLE_DEFAULT_SIZE; | ||||
nbuckets = sizehint / (ELFTC_STRING_TABLE_EXPECTED_CHAIN_LENGTH * | nbuckets = sizehint / (ELFTC_STRING_TABLE_EXPECTED_CHAIN_LENGTH * | ||||
Show All 30 Lines | elftc_string_table_destroy(Elftc_String_Table *st) | ||||
for (n = 0; n < st->st_nbuckets; n++) | for (n = 0; n < st->st_nbuckets; n++) | ||||
SLIST_FOREACH_SAFE(s, &st->st_buckets[n], ste_next, t) | SLIST_FOREACH_SAFE(s, &st->st_buckets[n], ste_next, t) | ||||
free(s); | free(s); | ||||
free(st->st_string_pool); | free(st->st_string_pool); | ||||
free(st); | free(st); | ||||
} | } | ||||
Elftc_String_Table * | Elftc_String_Table * | ||||
elftc_string_table_from_section(Elf_Scn *scn, int sizehint) | elftc_string_table_from_section(Elf_Scn *scn, size_t sizehint) | ||||
{ | { | ||||
int len; | int len; | ||||
Elf_Data *d; | Elf_Data *d; | ||||
GElf_Shdr sh; | GElf_Shdr sh; | ||||
const char *s, *end; | const char *s, *end; | ||||
Elftc_String_Table *st; | Elftc_String_Table *st; | ||||
/* Verify the type of the section passed in. */ | /* Verify the type of the section passed in. */ | ||||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |