source: rtems/cpukit/libmisc/untar/untar_tgz.c @ b2ed712

5
Last change on this file since b2ed712 was b2ed712, checked in by Sebastian Huber <sebastian.huber@…>, on 08/25/17 at 08:58:58

Include missing <string.h>

Update #2133.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <string.h>
20
21#include <rtems/untar.h>
22
23int Untar_GzChunkContext_Init(
24  Untar_GzChunkContext *ctx,
25  void *inflateBuffer,
26  size_t inflateBufferSize
27)
28{
29  int ret;
30  int status = UNTAR_SUCCESSFUL;
31
32  Untar_ChunkContext_Init(&ctx->base);
33  ctx->inflateBuffer = inflateBuffer;
34  ctx->inflateBufferSize = inflateBufferSize;
35  memset(&ctx->strm, 0, sizeof(ctx->strm));
36  ret = inflateInit2(&ctx->strm, 32 + MAX_WBITS);
37  if (ret != Z_OK){
38    status = UNTAR_FAIL;
39  }
40  return status;
41}
42
43int Untar_FromGzChunk_Print(
44  Untar_GzChunkContext *ctx,
45  void *chunk,
46  size_t chunk_size,
47  const rtems_printer *printer
48)
49{
50  int untar_succesful;
51  int status;
52
53  ctx->strm.next_in = (Bytef *)chunk;
54  ctx->strm.avail_in = (size_t)chunk_size;
55
56    /* Inflate until output buffer is not full */
57  do {
58    ctx->strm.next_out = (Bytef *) ctx->inflateBuffer;
59    ctx->strm.avail_out = ctx->inflateBufferSize;
60
61    status = inflate(&ctx->strm, Z_NO_FLUSH);
62    if (status == Z_OK || status == Z_STREAM_END) {
63      size_t inflated_size =
64        ctx->inflateBufferSize - ctx->strm.avail_out;
65      untar_succesful = Untar_FromChunk_Print(&ctx->base,
66        ctx->inflateBuffer, inflated_size, NULL);
67      if (untar_succesful != UNTAR_SUCCESSFUL){
68        return untar_succesful;
69      }
70    } else {
71      untar_succesful = UNTAR_GZ_INFLATE_FAILED;
72    }
73  } while (ctx->strm.avail_out == 0 && ctx->strm.avail_in > 0
74      && status == Z_OK);
75
76  if (status != Z_OK) {
77    if (untar_succesful != UNTAR_SUCCESSFUL){
78      rtems_printf(printer, "Untar not successful\n");
79    }
80
81    if (status != Z_STREAM_END) {
82      rtems_printf(printer, "Zlib inflate failed\n");
83    }
84
85    status = inflateEnd(&ctx->strm);
86    if (status != Z_OK) {
87      rtems_printf(printer, "Zlib inflate end failed\n");
88    }
89  }
90  return untar_succesful;
91}
92
93
Note: See TracBrowser for help on using the repository browser.