File: uncompress.c

package info (click to toggle)
nasm 3.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,660 kB
  • sloc: ansic: 129,101; asm: 40,471; perl: 8,238; sh: 4,146; makefile: 1,281; xml: 726; python: 582; lisp: 578; sed: 11
file content (51 lines) | stat: -rw-r--r-- 1,079 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* SPDX-License-Identifier: BSD-2-Clause */
/* Copyright 2025 The NASM Authors - All Rights Reserved */

/*
 * This needs to be in a separate file because zlib.h conflicts
 * with opflags.h.
 */
#include "compiler.h"
#include "zlib.h"
#include "macros.h"
#include "nasmlib.h"
#include "error.h"

/*
 * read line from standard macros set,
 * if there no more left -- return NULL
 */
static void *nasm_z_alloc(void *opaque, unsigned int items, unsigned int size)
{
    (void)opaque;
    return nasm_calloc(items, size);
}

static void nasm_z_free(void *opaque, void *ptr)
{
    (void)opaque;
    nasm_free(ptr);
}

char *uncompress_stdmac(macros_t *sm)
{
    z_stream zs;
    void *buf = nasm_malloc(sm->dsize);

    nasm_zero(zs);
    zs.next_in   = (void *)sm->zdata;
    zs.avail_in  = sm->zsize;
    zs.next_out  = buf;
    zs.avail_out = sm->dsize;
    zs.zalloc    = nasm_z_alloc;
    zs.zfree     = nasm_z_free;

    if (inflateInit2(&zs, 0) != Z_OK)
        panic();

    if (inflate(&zs, Z_FINISH) != Z_STREAM_END)
        panic();

    inflateEnd(&zs);
    return buf;
}