lib.c revision 48907
148907Srnordier/* 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 * $Id:$ 2748907Srnordier */ 2848907Srnordier 2948907Srnordier#include <sys/types.h> 3048907Srnordier#include <stddef.h> 3148907Srnordier 3248907Srnordier#include "kgzldr.h" 3348907Srnordier 3448907Srnordier#define MEMSIZ 0x8000 /* Memory pool size */ 3548907Srnordier 3648907Srnordierint kgz_con; /* Console control */ 3748907Srnordier 3848907Srnordierstatic size_t memtot; /* Memory allocated: bytes */ 3948907Srnordierstatic u_int memcnt; /* Memory allocated: blocks */ 4048907Srnordier 4148907Srnordier/* 4248907Srnordier * Library functions required by inflate(). 4348907Srnordier */ 4448907Srnordier 4548907Srnordier/* 4648907Srnordier * Allocate memory block. 4748907Srnordier */ 4848907Srnordierunsigned char * 4948907Srnordierkzipmalloc(int size) 5048907Srnordier{ 5148907Srnordier static u_char mem[MEMSIZ]; 5248907Srnordier void *ptr; 5348907Srnordier 5448907Srnordier if (memtot + size > MEMSIZ) 5548907Srnordier return NULL; 5648907Srnordier ptr = mem + memtot; 5748907Srnordier memtot += size; 5848907Srnordier memcnt++; 5948907Srnordier return ptr; 6048907Srnordier} 6148907Srnordier 6248907Srnordier/* 6348907Srnordier * Free allocated memory block. 6448907Srnordier */ 6548907Srnordiervoid 6648907Srnordierkzipfree(void *ptr) 6748907Srnordier{ 6848907Srnordier memcnt--; 6948907Srnordier if (!memcnt) 7048907Srnordier memtot = 0; 7148907Srnordier} 7248907Srnordier 7348907Srnordier/* 7448907Srnordier * Write a string to the console. 7548907Srnordier */ 7648907Srnordiervoid 7748907Srnordierputstr(const char *str) 7848907Srnordier{ 7948907Srnordier int c; 8048907Srnordier 8148907Srnordier while ((c = *str++)) { 8248907Srnordier if (kgz_con & KGZ_CRT) 8348907Srnordier crt_putchr(c); 8448907Srnordier if (kgz_con & KGZ_SIO) 8548907Srnordier sio_putchr(c); 8648907Srnordier } 8748907Srnordier} 88