Skip to content

Commit d645616

Browse files
updated libmysofa
1 parent 8b07bfe commit d645616

File tree

8 files changed

+1162
-973
lines changed

8 files changed

+1162
-973
lines changed

framework/modules/saf_sofa_reader/libmysofa/internal/hdf_dataobject.c

Lines changed: 124 additions & 113 deletions
Large diffs are not rendered by default.

framework/modules/saf_sofa_reader/libmysofa/internal/hdf_fractalhead.c

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
#define MAX_NAME_LENGTH (0x100)
4646

47-
static int log2i(int a) { return (int)round(log2(a)); }
47+
static int log2i(int a) { return round(log2(a)); }
4848

4949
static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
5050
struct FRACTALHEAP *fractalheap) {
@@ -69,37 +69,37 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
6969
reader->recursive_counter++;
7070

7171
/* read signature */
72-
if (fread(buf, 1, 4, reader->fhd) != 4 || strncmp(buf, "FHDB", 4)) {
72+
if (mysofa_read(reader, buf, 4) != 4 || strncmp(buf, "FHDB", 4)) {
7373
// LCOV_EXCL_START
7474
mylog("cannot read signature of fractal heap indirect block\n");
7575
return MYSOFA_INVALID_FORMAT;
7676
// LCOV_EXCL_STOP
7777
}
7878
buf[4] = 0;
79-
mylog("%08" PRIX64 " %.4s stack %d\n", (uint64_t)ftell(reader->fhd) - 4, buf,
79+
mylog("%08" PRIX64 " %.4s stack %d\n", (uint64_t)mysofa_tell(reader) - 4, buf,
8080
reader->recursive_counter);
8181

82-
if (fgetc(reader->fhd) != 0) {
82+
if (mysofa_getc(reader) != 0) {
8383
mylog("object FHDB must have version 0\n"); // LCOV_EXCL_LINE
8484
return MYSOFA_UNSUPPORTED_FORMAT; // LCOV_EXCL_LINE
8585
}
8686

8787
/* ignore heap_header_address */
88-
if (fseek(reader->fhd, reader->superblock.size_of_offsets, SEEK_CUR) < 0)
88+
if (mysofa_seek(reader, reader->superblock.size_of_offsets, SEEK_CUR) < 0)
8989
return errno; // LCOV_EXCL_LINE
9090

9191
size = (fractalheap->maximum_heap_size + 7) / 8;
9292
block_offset = readValue(reader, size);
9393

9494
if (fractalheap->flags & 2)
95-
if (fseek(reader->fhd, 4, SEEK_CUR))
95+
if (mysofa_seek(reader, 4, SEEK_CUR))
9696
return errno; // LCOV_EXCL_LINE
9797

98-
offset_size = (int)ceilf(log2f(fractalheap->maximum_heap_size) / 8);
98+
offset_size = ceilf(log2f(fractalheap->maximum_heap_size) / 8);
9999
if (fractalheap->maximum_direct_block_size < fractalheap->maximum_size)
100-
length_size = (int)ceilf(log2f((float)fractalheap->maximum_direct_block_size) / 8);
100+
length_size = ceilf(log2f(fractalheap->maximum_direct_block_size) / 8);
101101
else
102-
length_size = (int)ceilf(log2f((float)fractalheap->maximum_size) / 8);
102+
length_size = ceilf(log2f(fractalheap->maximum_size) / 8);
103103

104104
mylog(" %d %" PRIu64 " %d\n", size, block_offset, offset_size);
105105

@@ -136,14 +136,14 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
136136
137137
*/
138138
do {
139-
typeandversion = (uint8_t)fgetc(reader->fhd);
139+
typeandversion = (uint8_t)mysofa_getc(reader);
140140
offset = readValue(reader, offset_size);
141141
length = readValue(reader, length_size);
142142
if (offset > 0x10000000 || length > 0x10000000)
143143
return MYSOFA_UNSUPPORTED_FORMAT; // LCOV_EXCL_LINE
144144

145145
mylog(" %d %4" PRIX64 " %" PRIX64 " %08lX\n", typeandversion, offset,
146-
length, ftell(reader->fhd) - 1 - offset_size - length_size);
146+
length, mysofa_tell(reader) - 1 - offset_size - length_size);
147147

148148
/* TODO: for the following part, the specification is incomplete */
149149
if (typeandversion == 3) {
@@ -158,7 +158,7 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
158158

159159
if (!(name = malloc(length + 1)))
160160
return MYSOFA_NO_MEMORY; // LCOV_EXCL_LINE
161-
if (fread(name, 1, length, reader->fhd) != length) {
161+
if (mysofa_read(reader, name, length) != (int)length) {
162162
free(name); // LCOV_EXCL_LINE
163163
return MYSOFA_READ_ERROR; // LCOV_EXCL_LINE
164164
}
@@ -185,7 +185,7 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
185185
free(name); // LCOV_EXCL_LINE
186186
return MYSOFA_NO_MEMORY; // LCOV_EXCL_LINE
187187
}
188-
if ( (int)fread(value, 1, len, reader->fhd) != len) {
188+
if (mysofa_read(reader, value, len) != len) {
189189
free(value); // LCOV_EXCL_LINE
190190
free(name); // LCOV_EXCL_LINE
191191
return MYSOFA_READ_ERROR; // LCOV_EXCL_LINE
@@ -200,7 +200,7 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
200200
} else {
201201
mylog("FHDB type 3 unsupported values: %12" PRIX64 "\n", unknown1);
202202
free(name);
203-
/* TODO: return MYSOFA_UNSUPPORTED_FORMAT; */
203+
/* TODO: return MYSOFA_UNSUPPORTED_FORMAT; */
204204
return MYSOFA_OK;
205205
}
206206
mylog(" %s = %s\n", name, value);
@@ -228,15 +228,15 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
228228
if (unknown3 != 0x0000)
229229
return MYSOFA_INVALID_FORMAT;
230230

231-
len = fgetc(reader->fhd);
231+
len = mysofa_getc(reader);
232232
if (len < 0)
233233
return MYSOFA_READ_ERROR; // LCOV_EXCL_LINE
234234
if (len > MAX_NAME_LENGTH)
235235
return MYSOFA_INVALID_FORMAT; // LCOV_EXCL_LINE
236236

237237
if (!(name = malloc(len + 1)))
238238
return MYSOFA_NO_MEMORY; // LCOV_EXCL_LINE
239-
if ((int)fread(name, 1, len, reader->fhd) != len) {
239+
if (mysofa_read(reader, name, len) != len) {
240240
free(name); // LCOV_EXCL_LINE
241241
return MYSOFA_READ_ERROR; // LCOV_EXCL_LINE
242242
}
@@ -259,8 +259,8 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
259259
dir->next = dataobject->directory;
260260
dataobject->directory = dir;
261261

262-
store = ftell(reader->fhd);
263-
if (fseek(reader->fhd, (long)heap_header_address, SEEK_SET)) {
262+
store = mysofa_tell(reader);
263+
if (mysofa_seek(reader, heap_header_address, SEEK_SET)) {
264264
free(name); // LCOV_EXCL_LINE
265265
return errno; // LCOV_EXCL_LINE
266266
}
@@ -273,7 +273,7 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
273273
if (store < 0) {
274274
return errno; // LCOV_EXCL_LINE
275275
}
276-
if (fseek(reader->fhd, store, SEEK_SET) < 0)
276+
if (mysofa_seek(reader, store, SEEK_SET) < 0)
277277
return errno; // LCOV_EXCL_LINE
278278
break;
279279
case 0x00080008:
@@ -347,7 +347,7 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
347347
return MYSOFA_NO_MEMORY; // LCOV_EXCL_LINE
348348
len = -1;
349349
for (int i = 0; i < MAX_NAME_LENGTH; i++) {
350-
int c = fgetc(reader->fhd);
350+
int c = mysofa_getc(reader);
351351
if (c < 0 || i == MAX_NAME_LENGTH - 1) {
352352
free(name); // LCOV_EXCL_LINE
353353
return MYSOFA_READ_ERROR; // LCOV_EXCL_LINE
@@ -391,7 +391,7 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
391391
free(name); // LCOV_EXCL_LINE
392392
return MYSOFA_NO_MEMORY; // LCOV_EXCL_LINE
393393
}
394-
if ((int)fread(value, 1, len, reader->fhd) != len) {
394+
if (mysofa_read(reader, value, len) != len) {
395395
free(value); // LCOV_EXCL_LINE
396396
free(name); // LCOV_EXCL_LINE
397397
return MYSOFA_READ_ERROR; // LCOV_EXCL_LINE
@@ -416,14 +416,14 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
416416
// LCOV_EXCL_START
417417
default:
418418
mylog("FHDB type 1 unsupported values %08" PRIX64 " %" PRIX64 "\n",
419-
unknown2, (uint64_t)ftell(reader->fhd) - 4);
419+
unknown2, (uint64_t)mysofa_tell(reader) - 4);
420420
return MYSOFA_UNSUPPORTED_FORMAT;
421421
// LCOV_EXCL_STOP
422422
}
423423
} else if (typeandversion != 0) {
424424
/* TODO is must be avoided somehow */
425425
mylog("fractal head unknown type %d\n", typeandversion);
426-
/* return MYSOFA_UNSUPPORTED_FORMAT; */
426+
/* return MYSOFA_UNSUPPORTED_FORMAT; */
427427
return MYSOFA_OK;
428428
}
429429

@@ -454,14 +454,14 @@ static int indirectblockRead(struct READER *reader,
454454
UNUSED(filter_mask);
455455

456456
/* read signature */
457-
if (fread(buf, 1, 4, reader->fhd) != 4 || strncmp(buf, "FHIB", 4)) {
457+
if (mysofa_read(reader, buf, 4) != 4 || strncmp(buf, "FHIB", 4)) {
458458
mylog("cannot read signature of fractal heap indirect block\n");
459459
return MYSOFA_INVALID_FORMAT;
460460
}
461461
buf[4] = 0;
462-
mylog("%08" PRIX64 " %.4s\n", (uint64_t)ftell(reader->fhd) - 4, buf);
462+
mylog("%08" PRIX64 " %.4s\n", (uint64_t)mysofa_tell(reader) - 4, buf);
463463

464-
if (fgetc(reader->fhd) != 0) {
464+
if (mysofa_getc(reader) != 0) {
465465
mylog("object FHIB must have version 0\n");
466466
return MYSOFA_UNSUPPORTED_FORMAT;
467467
}
@@ -477,7 +477,7 @@ static int indirectblockRead(struct READER *reader,
477477
return MYSOFA_UNSUPPORTED_FORMAT;
478478
}
479479

480-
/* The number of rows of blocks, nrows, in an indirect block of size
480+
/* The number of rows of blocks, nrows, in an indirect block of size
481481
* iblock_size is given by the following expression: */
482482
nrows = (log2i((int)iblock_size) - log2i((int)fractalheap->starting_block_size)) + 1;
483483

@@ -508,15 +508,15 @@ static int indirectblockRead(struct READER *reader,
508508
}
509509
mylog(">> %d %" PRIX64 " %d\n", k, child_direct_block, size);
510510
if (validAddress(reader, child_direct_block)) {
511-
store = ftell(reader->fhd);
512-
if (fseek(reader->fhd, (long)child_direct_block, SEEK_SET) < 0)
511+
store = mysofa_tell(reader);
512+
if (mysofa_seek(reader, child_direct_block, SEEK_SET) < 0)
513513
return errno;
514514
err = directblockRead(reader, dataobject, fractalheap);
515515
if (err)
516516
return err;
517517
if (store < 0)
518518
return MYSOFA_READ_ERROR;
519-
if (fseek(reader->fhd, store, SEEK_SET) < 0)
519+
if (mysofa_seek(reader, store, SEEK_SET) < 0)
520520
return errno;
521521
}
522522

@@ -528,15 +528,15 @@ static int indirectblockRead(struct READER *reader,
528528
readValue(reader, reader->superblock.size_of_offsets);
529529

530530
if (validAddress(reader, child_direct_block)) {
531-
store = ftell(reader->fhd);
532-
if (fseek(reader->fhd, (long)child_indirect_block, SEEK_SET) < 0)
531+
store = mysofa_tell(reader);
532+
if (mysofa_seek(reader, child_indirect_block, SEEK_SET) < 0)
533533
return errno;
534534
err = indirectblockRead(reader, dataobject, fractalheap, iblock_size * 2);
535535
if (err)
536536
return err;
537537
if (store < 0)
538538
return MYSOFA_READ_ERROR;
539-
if (fseek(reader->fhd, store, SEEK_SET) < 0)
539+
if (mysofa_seek(reader, store, SEEK_SET) < 0)
540540
return errno;
541541
}
542542

@@ -567,14 +567,14 @@ int fractalheapRead(struct READER *reader, struct DATAOBJECT *dataobject,
567567
char buf[5];
568568

569569
/* read signature */
570-
if (fread(buf, 1, 4, reader->fhd) != 4 || strncmp(buf, "FRHP", 4)) {
570+
if (mysofa_read(reader, buf, 4) != 4 || strncmp(buf, "FRHP", 4)) {
571571
mylog("cannot read signature of fractal heap\n");
572572
return MYSOFA_UNSUPPORTED_FORMAT;
573573
}
574574
buf[4] = 0;
575-
mylog("%" PRIX64 " %.4s\n", (uint64_t)ftell(reader->fhd) - 4, buf);
575+
mylog("%" PRIX64 " %.4s\n", (uint64_t)mysofa_tell(reader) - 4, buf);
576576

577-
if (fgetc(reader->fhd) != 0) {
577+
if (mysofa_getc(reader) != 0) {
578578
mylog("object fractal heap must have version 0\n");
579579
return MYSOFA_UNSUPPORTED_FORMAT;
580580
}
@@ -583,7 +583,7 @@ int fractalheapRead(struct READER *reader, struct DATAOBJECT *dataobject,
583583
fractalheap->encoded_length = (uint16_t)readValue(reader, 2);
584584
if (fractalheap->encoded_length > 0x8000)
585585
return MYSOFA_UNSUPPORTED_FORMAT;
586-
fractalheap->flags = (uint8_t)fgetc(reader->fhd);
586+
fractalheap->flags = (uint8_t)mysofa_getc(reader);
587587
fractalheap->maximum_size = (uint32_t)readValue(reader, 4);
588588

589589
fractalheap->next_huge_object_id =
@@ -636,13 +636,14 @@ int fractalheapRead(struct READER *reader, struct DATAOBJECT *dataobject,
636636
if (!fractalheap->filter_information)
637637
return MYSOFA_NO_MEMORY;
638638

639-
if (fread(fractalheap->filter_information, 1, fractalheap->encoded_length,
640-
reader->fhd) != fractalheap->encoded_length) {
639+
if (mysofa_read(reader, fractalheap->filter_information,
640+
fractalheap->encoded_length) !=
641+
fractalheap->encoded_length) {
641642
return MYSOFA_READ_ERROR;
642643
}
643644
}
644645

645-
if (fseek(reader->fhd, 4, SEEK_CUR) < 0) { /* skip checksum */
646+
if (mysofa_seek(reader, 4, SEEK_CUR) < 0) { /* skip checksum */
646647
return MYSOFA_READ_ERROR;
647648
}
648649

@@ -658,7 +659,7 @@ int fractalheapRead(struct READER *reader, struct DATAOBJECT *dataobject,
658659

659660
if (validAddress(reader, fractalheap->address_of_root_block)) {
660661

661-
if (fseek(reader->fhd, (long)fractalheap->address_of_root_block, SEEK_SET) < 0)
662+
if (mysofa_seek(reader, fractalheap->address_of_root_block, SEEK_SET) < 0)
662663
return errno;
663664
if (fractalheap->current_row)
664665
err = indirectblockRead(reader, dataobject, fractalheap,
@@ -677,6 +678,7 @@ void fractalheapFree(struct FRACTALHEAP *fractalheap) {
677678
free(fractalheap->filter_information);
678679
}
679680

681+
680682
#else
681683
extern int to_avoid_iso_compiler_warning_when_there_are_no_symbols;
682684
#endif /* SAF_ENABLE_SOFA_READER_MODULE */

0 commit comments

Comments
 (0)