File indexing completed on 2025-05-11 08:24:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include <string.h>
0033
0034 #include <rtems/untar.h>
0035
0036 int Untar_GzChunkContext_Init(
0037 Untar_GzChunkContext *ctx,
0038 void *inflateBuffer,
0039 size_t inflateBufferSize
0040 )
0041 {
0042 int ret;
0043 int status = UNTAR_SUCCESSFUL;
0044
0045 Untar_ChunkContext_Init(&ctx->base);
0046 ctx->inflateBuffer = inflateBuffer;
0047 ctx->inflateBufferSize = inflateBufferSize;
0048 memset(&ctx->strm, 0, sizeof(ctx->strm));
0049 ret = inflateInit2(&ctx->strm, 32 + MAX_WBITS);
0050 if (ret != Z_OK){
0051 status = UNTAR_FAIL;
0052 }
0053 return status;
0054 }
0055
0056 int Untar_FromGzChunk_Print(
0057 Untar_GzChunkContext *ctx,
0058 void *chunk,
0059 size_t chunk_size,
0060 const rtems_printer *printer
0061 )
0062 {
0063 int untar_succesful;
0064 int status;
0065
0066 ctx->strm.next_in = (Bytef *)chunk;
0067 ctx->strm.avail_in = (size_t)chunk_size;
0068
0069
0070 do {
0071 ctx->strm.next_out = (Bytef *) ctx->inflateBuffer;
0072 ctx->strm.avail_out = ctx->inflateBufferSize;
0073
0074 status = inflate(&ctx->strm, Z_NO_FLUSH);
0075 if (status == Z_OK || status == Z_STREAM_END) {
0076 size_t inflated_size =
0077 ctx->inflateBufferSize - ctx->strm.avail_out;
0078 untar_succesful = Untar_FromChunk_Print(&ctx->base,
0079 ctx->inflateBuffer, inflated_size, NULL);
0080 if (untar_succesful != UNTAR_SUCCESSFUL){
0081 return untar_succesful;
0082 }
0083 } else {
0084 untar_succesful = UNTAR_GZ_INFLATE_FAILED;
0085 }
0086 } while (ctx->strm.avail_out == 0 && ctx->strm.avail_in > 0
0087 && status == Z_OK);
0088
0089 if (status != Z_OK) {
0090 if (untar_succesful != UNTAR_SUCCESSFUL){
0091 rtems_printf(printer, "Untar not successful\n");
0092 }
0093
0094 if (status != Z_STREAM_END) {
0095 rtems_printf(printer, "Zlib inflate failed\n");
0096 }
0097
0098 status = inflateEnd(&ctx->strm);
0099 if (status != Z_OK) {
0100 rtems_printf(printer, "Zlib inflate end failed\n");
0101 }
0102 }
0103 return untar_succesful;
0104 }
0105
0106