diff options
Diffstat (limited to 'modules/libmar/src')
-rw-r--r-- | modules/libmar/src/mar.h | 1 | ||||
-rw-r--r-- | modules/libmar/src/mar_read.c | 22 |
2 files changed, 19 insertions, 4 deletions
diff --git a/modules/libmar/src/mar.h b/modules/libmar/src/mar.h index 98b454d94..776daf648 100644 --- a/modules/libmar/src/mar.h +++ b/modules/libmar/src/mar.h @@ -48,6 +48,7 @@ typedef struct MarItem_ { struct MarFile_ { FILE *fp; MarItem *item_table[TABLESIZE]; + int item_table_is_valid; }; typedef struct MarFile_ MarFile; diff --git a/modules/libmar/src/mar_read.c b/modules/libmar/src/mar_read.c index 17744cdfc..378eaea88 100644 --- a/modules/libmar/src/mar_read.c +++ b/modules/libmar/src/mar_read.c @@ -114,6 +114,7 @@ static int mar_read_index(MarFile *mar) { uint32_t offset_to_index, size_of_index; /* verify MAR ID */ + fseek(mar->fp, 0, SEEK_SET); if (fread(id, MAR_ID_SIZE, 1, mar->fp) != 1) return -1; if (memcmp(id, MAR_ID, MAR_ID_SIZE) != 0) @@ -160,11 +161,8 @@ static MarFile *mar_fpopen(FILE *fp) } mar->fp = fp; + mar->item_table_is_valid = 0; memset(mar->item_table, 0, sizeof(mar->item_table)); - if (mar_read_index(mar)) { - mar_close(mar); - return NULL; - } return mar; } @@ -490,6 +488,14 @@ const MarItem *mar_find_item(MarFile *mar, const char *name) { uint32_t hash; const MarItem *item; + if (!mar->item_table_is_valid) { + if (mar_read_index(mar)) { + return NULL; + } else { + mar->item_table_is_valid = 1; + } + } + hash = mar_hash_name(name); item = mar->item_table[hash]; @@ -503,6 +509,14 @@ int mar_enum_items(MarFile *mar, MarItemCallback callback, void *closure) { MarItem *item; int i; + if (!mar->item_table_is_valid) { + if (mar_read_index(mar)) { + return -1; + } else { + mar->item_table_is_valid = 1; + } + } + for (i = 0; i < TABLESIZE; ++i) { item = mar->item_table[i]; while (item) { |