| 454 | } |
| 455 | |
| 456 | static boolean |
| 457 | read_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 | |
| 493 | static void |
| 494 | free_data_block(struct DataBlock *block) |
no test coverage detected