diff options
| author | Pixel <pixel@nobis-crew.org> | 2009-02-17 03:14:49 +0100 | 
|---|---|---|
| committer | Pixel <pixel@nobis-crew.org> | 2009-02-17 03:14:49 +0100 | 
| commit | daabda7c8b4038ac24cdf5b9790932905eab7d8f (patch) | |
| tree | 02cd32b465f962b7219db5c26409883f2be25cda /mpq-fs.c | |
| parent | 7014696a982451f4af8903b8da8b915cdcbdf632 (diff) | |
Improving stalloc by make it context-safe.
Diffstat (limited to 'mpq-fs.c')
| -rw-r--r-- | mpq-fs.c | 17 | 
1 files changed, 7 insertions, 10 deletions
| @@ -28,6 +28,7 @@ static char * strnormalize(char * _str) {  }  htab * hash_table = 0; +struct st_alloc_t * st = 0;  static void add_file(struct mpq_archive_t * mpq_a, char * fname) {      int entry; @@ -36,13 +37,15 @@ static void add_file(struct mpq_archive_t * mpq_a, char * fname) {      if ((entry = mpqlib_find_hash_entry_by_name(mpq_a, fname, 0, 0)) < 0)          return; -    if (!hash_table) +    if (!hash_table) {          hash_table = hcreate(INITIAL_HASH_SIZE); +        st = st_init(); +    } -    nfname = strnormalize(st_strdup(fname));     +    nfname = strnormalize(st_strdup(st, fname));      hadd(hash_table, (uint8_t *) nfname, strlen(nfname), NULL);      if (!hstuff(hash_table)) { -        hstuff(hash_table) = st_alloc(sizeof(hash_entry)); +        hstuff(hash_table) = st_alloc(st, sizeof(hash_entry));      }      ((hash_entry *) hstuff(hash_table))->mpq_a = mpq_a;      ((hash_entry *) hstuff(hash_table))->entry = entry; @@ -155,14 +158,8 @@ int mpqlib_fs_filelist(char * buffer) {  void mpqlib_fs_shutdown() {      if (!hash_table)          return; -/* -    if (hfirst(hash_table)) do { -        free(hstuff(hash_table)); -        free(hkey(hash_table)); -    } while (hnext(hash_table)); -*/ -    st_shutdown(); +    st_destroy(st);      hdestroy(hash_table);      hash_table = 0;  } | 
