Mercurial > hg > dmlib
comparison src/dmres.c @ 2479:c1cae47cd410
Rename DMPackEntry::length to csize (compressed size).
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 27 Apr 2020 21:33:29 +0300 |
parents | 8193f62a541d |
children | 92b93a12c014 |
comparison
equal
deleted
inserted
replaced
2478:0d13de7edb30 | 2479:c1cae47cd410 |
---|---|
386 | 386 |
387 // Initialize decompression | 387 // Initialize decompression |
388 memset(&zstr, 0, sizeof(zstr)); | 388 memset(&zstr, 0, sizeof(zstr)); |
389 zstr.next_out = handle->memData; | 389 zstr.next_out = handle->memData; |
390 zstr.avail_out = handle->memSize; | 390 zstr.avail_out = handle->memSize; |
391 cdataLeft = node->length; | 391 cdataLeft = node->csize; |
392 | 392 |
393 if ((zret = inflateInit(&zstr)) != Z_OK) | 393 if ((zret = inflateInit(&zstr)) != Z_OK) |
394 { | 394 { |
395 ret = dmErrorDBG(DMERR_INIT_FAIL, | 395 ret = dmErrorDBG(DMERR_INIT_FAIL, |
396 "Could not initialize zlib stream decompression.\n"); | 396 "Could not initialize zlib stream decompression.\n"); |
428 DMZLibContext zctx; | 428 DMZLibContext zctx; |
429 Uint8 *inBuf = NULL; | 429 Uint8 *inBuf = NULL; |
430 int ret; | 430 int ret; |
431 | 431 |
432 // Allocate buffer for compressed data | 432 // Allocate buffer for compressed data |
433 if ((inBuf = dmMalloc(node->length)) == NULL) | 433 if ((inBuf = dmMalloc(node->csize)) == NULL) |
434 { | 434 { |
435 ret = DMERR_MALLOC; | 435 ret = DMERR_MALLOC; |
436 goto out; | 436 goto out; |
437 } | 437 } |
438 | 438 |
439 // Read compressed data | 439 // Read compressed data |
440 if (fread(inBuf, sizeof(Uint8), node->length, handle->lib->packFile->file) != node->length) | 440 if (fread(inBuf, sizeof(Uint8), node->csize, handle->lib->packFile->file) != node->csize) |
441 { | 441 { |
442 ret = DMERR_FREAD; | 442 ret = DMERR_FREAD; |
443 goto out; | 443 goto out; |
444 } | 444 } |
445 | 445 |
446 // Initialize decompression structures | 446 // Initialize decompression structures |
447 if ((ret = dmZLibInitInflate(&zctx)) != DMERR_OK) | 447 if ((ret = dmZLibInitInflate(&zctx)) != DMERR_OK) |
448 goto out; | 448 goto out; |
449 | 449 |
450 zctx.inBuffer = zctx.inBufferStart = inBuf; | 450 zctx.inBuffer = zctx.inBufferStart = inBuf; |
451 zctx.inBufferEnd = inBuf + node->length; | 451 zctx.inBufferEnd = inBuf + node->csize; |
452 zctx.outBuffer = zctx.outBufferStart = handle->memData; | 452 zctx.outBuffer = zctx.outBufferStart = handle->memData; |
453 zctx.outBufferEnd = handle->memData + node->size; | 453 zctx.outBufferEnd = handle->memData + node->size; |
454 zctx.expandable = FALSE; | 454 zctx.expandable = FALSE; |
455 | 455 |
456 // Attempt decompression | 456 // Attempt decompression |
520 handle->filename, handle->memSize, node->size); | 520 handle->filename, handle->memSize, node->size); |
521 } | 521 } |
522 } | 522 } |
523 else | 523 else |
524 { | 524 { |
525 if (node->size != node->length) | 525 if (node->size != node->csize) |
526 { | 526 { |
527 ret = dmErrorDBG(DMERR_INVALID_DATA, | 527 ret = dmErrorDBG(DMERR_INVALID_DATA, |
528 "Node '%s' raw size and length fields differ for uncompressed node: %d <> %d.\n", | 528 "Node '%s' raw size and length fields differ for uncompressed node: %d <> %d.\n", |
529 handle->filename, node->size, node->length); | 529 handle->filename, node->size, node->csize); |
530 goto out; | 530 goto out; |
531 } | 531 } |
532 if (fread(handle->memData, sizeof(Uint8), node->size, handle->lib->packFile->file) != node->size) | 532 if (fread(handle->memData, sizeof(Uint8), node->size, handle->lib->packFile->file) != node->size) |
533 { | 533 { |
534 ret = dmErrorDBG(DMERR_FREAD, | 534 ret = dmErrorDBG(DMERR_FREAD, |
705 static int dm_mem_fputc(int ch, DMResource *ctx) | 705 static int dm_mem_fputc(int ch, DMResource *ctx) |
706 { | 706 { |
707 // Check for EOF | 707 // Check for EOF |
708 if (!dm_mem_realloc(ctx, ctx->memOffset + 1)) | 708 if (!dm_mem_realloc(ctx, ctx->memOffset + 1)) |
709 return EOF; | 709 return EOF; |
710 | 710 |
711 ctx->memData[ctx->memOffset++] = ch; | 711 ctx->memData[ctx->memOffset++] = ch; |
712 return ch; | 712 return ch; |
713 } | 713 } |
714 | 714 |
715 | 715 |