1119482Sobrien/*-
248907Srnordier * Copyright (c) 1999 Global Technology Associates, Inc.
348907Srnordier * All rights reserved.
448907Srnordier *
548907Srnordier * Redistribution and use in source and binary forms, with or without
648907Srnordier * modification, are permitted provided that the following conditions
748907Srnordier * are met:
848907Srnordier * 1. Redistributions of source code must retain the above copyright
948907Srnordier *    notice, this list of conditions and the following disclaimer.
1048907Srnordier * 2. Redistributions in binary form must reproduce the above copyright
1148907Srnordier *    notice, this list of conditions and the following disclaimer in the
1248907Srnordier *    documentation and/or other materials provided with the distribution.
1348907Srnordier *
1448907Srnordier * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND
1548907Srnordier * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1648907Srnordier * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1748907Srnordier * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
1848907Srnordier * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
1948907Srnordier * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
2048907Srnordier * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
2148907Srnordier * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2248907Srnordier * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2348907Srnordier * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
2448907Srnordier * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2548907Srnordier */
2648907Srnordier
27119482Sobrien#include <sys/cdefs.h>
28119482Sobrien__FBSDID("$FreeBSD: stable/11/stand/i386/kgzldr/lib.c 119482 2003-08-25 23:28:32Z obrien $");
29119482Sobrien
3048907Srnordier#include <sys/types.h>
3148907Srnordier#include <stddef.h>
3248907Srnordier
3348907Srnordier#include "kgzldr.h"
3448907Srnordier
3548907Srnordier#define MEMSIZ  0x8000		/* Memory pool size */
3648907Srnordier
3748907Srnordierint kgz_con;			/* Console control */
3848907Srnordier
3948907Srnordierstatic size_t memtot;		/* Memory allocated: bytes */
4048907Srnordierstatic u_int memcnt;		/* Memory allocated: blocks */
4148907Srnordier
4248907Srnordier/*
4348907Srnordier * Library functions required by inflate().
4448907Srnordier */
4548907Srnordier
4648907Srnordier/*
4748907Srnordier * Allocate memory block.
4848907Srnordier */
4948907Srnordierunsigned char *
5048907Srnordierkzipmalloc(int size)
5148907Srnordier{
5248907Srnordier    static u_char mem[MEMSIZ];
5348907Srnordier    void *ptr;
5448907Srnordier
5548907Srnordier    if (memtot + size > MEMSIZ)
5648907Srnordier        return NULL;
5748907Srnordier    ptr = mem + memtot;
5848907Srnordier    memtot += size;
5948907Srnordier    memcnt++;
6048907Srnordier    return ptr;
6148907Srnordier}
6248907Srnordier
6348907Srnordier/*
6448907Srnordier * Free allocated memory block.
6548907Srnordier */
6648907Srnordiervoid
6748907Srnordierkzipfree(void *ptr)
6848907Srnordier{
6948907Srnordier    memcnt--;
7048907Srnordier    if (!memcnt)
7148907Srnordier        memtot = 0;
7248907Srnordier}
7348907Srnordier
7448907Srnordier/*
7548907Srnordier * Write a string to the console.
7648907Srnordier */
7748907Srnordiervoid
7848907Srnordierputstr(const char *str)
7948907Srnordier{
8048907Srnordier    int c;
8148907Srnordier
8248907Srnordier    while ((c = *str++)) {
8348907Srnordier        if (kgz_con & KGZ_CRT)
8448907Srnordier            crt_putchr(c);
8548907Srnordier        if (kgz_con & KGZ_SIO)
8648907Srnordier            sio_putchr(c);
8748907Srnordier    }
8848907Srnordier}
89