summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-09-11 20:10:43 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-09-11 20:10:43 +0200
commit2713347f0e0ec3014501c35cd53900732fd27176 (patch)
tree23d1c8f675ea7582fe3609039f86195764b8bd97 /modules
parent1bf4a513c8e7fd85642827ce0938b7e1441e5e03 (diff)
parentd086e918b45bbc7a841b46c3d444b2e9d7d7e4c3 (diff)
downloadUXP-2713347f0e0ec3014501c35cd53900732fd27176.tar
UXP-2713347f0e0ec3014501c35cd53900732fd27176.tar.gz
UXP-2713347f0e0ec3014501c35cd53900732fd27176.tar.lz
UXP-2713347f0e0ec3014501c35cd53900732fd27176.tar.xz
UXP-2713347f0e0ec3014501c35cd53900732fd27176.zip
Merge branch 'ported-upstream'
Diffstat (limited to 'modules')
-rw-r--r--modules/libmar/src/mar.h1
-rw-r--r--modules/libmar/src/mar_read.c22
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) {