MCPcopy Create free account
hub / github.com/NetHack/NetHack / read_data_block

Function read_data_block

win/share/giftiles.c:456–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

454}
455
456static boolean
457read_data_block(struct Bitstream *gif, struct DataBlock *block)
458{
459 long pos = ftell(gif->fp);
460 int b;
461 size_t i;
462
463 free_data_block(block);
464
465 /* Get the length of the data block */
466 while (TRUE) {
467 b = fgetc(gif->fp);
468 if (b == EOF) return FALSE;
469 if (b == 0) break;
470 block->size += b;
471 fseek(gif->fp, b, SEEK_CUR);
472 }
473 fseek(gif->fp, pos, SEEK_SET);
474
475 /* Allocate memory */
476 block->data = (unsigned char *) alloc(block->size);
477
478 /* Read the data from the file */
479 i = 0;
480 while (TRUE) {
481 b = fgetc(gif->fp);
482 if (b == EOF) return FALSE;
483 if (b == 0) break;
484 if (fread(block->data + i, 1, b, gif->fp) != (unsigned) b)
485 return FALSE;
486 i += b;
487 }
488
489 block->index = 0;
490 return TRUE;
491}
492
493static void
494free_data_block(struct DataBlock *block)

Callers 1

read_gif_tilesFunction · 0.85

Calls 6

ftellFunction · 0.85
free_data_blockFunction · 0.85
fgetcFunction · 0.85
fseekFunction · 0.85
freadFunction · 0.85
allocFunction · 0.50

Tested by

no test coverage detected