sbrk.c revision 39665
139665Smsmith/*-
239665Smsmith * Copyright (c) 1998 Michael Smith
339665Smsmith * All rights reserved.
439665Smsmith *
539665Smsmith * Redistribution and use in source and binary forms, with or without
639665Smsmith * modification, are permitted provided that the following conditions
739665Smsmith * are met:
839665Smsmith * 1. Redistributions of source code must retain the above copyright
939665Smsmith *    notice, this list of conditions and the following disclaimer.
1039665Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1139665Smsmith *    notice, this list of conditions and the following disclaimer in the
1239665Smsmith *    documentation and/or other materials provided with the distribution.
1339665Smsmith *
1439665Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1539665Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1639665Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1739665Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1839665Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1939665Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2039665Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2139665Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2239665Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2339665Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2439665Smsmith * SUCH DAMAGE.
2539665Smsmith *
2639665Smsmith *	$Id$
2739665Smsmith */
2839665Smsmith
2939665Smsmith/*
3039665Smsmith * Minimal sbrk() emulation required for malloc support.
3139665Smsmith */
3239665Smsmith
3339665Smsmith#include <string.h>
3439665Smsmith#include "stand.h"
3539665Smsmith
3639665Smsmithstatic size_t	maxheap, heapsize = 0;
3739665Smsmithstatic void	*heapbase;
3839665Smsmith
3939665Smsmithvoid
4039665Smsmithsetheap(void *base, void *top)
4139665Smsmith{
4239665Smsmith    heapbase = base;
4339665Smsmith    maxheap = top - base;
4439665Smsmith}
4539665Smsmith
4639665Smsmithchar *
4739665Smsmithsbrk(int incr)
4839665Smsmith{
4939665Smsmith    char	*ret;
5039665Smsmith
5139665Smsmith    if ((heapsize + incr) <= maxheap) {
5239665Smsmith	ret = heapbase + heapsize;
5339665Smsmith	bzero(ret, incr);
5439665Smsmith	heapsize += incr;
5539665Smsmith	return(ret);
5639665Smsmith    }
5739665Smsmith    errno = ENOMEM;
5839665Smsmith    return((char *)-1);
5939665Smsmith}
6039665Smsmith
61