/	Copyright (c) 1984, 1986, 1987, 1988 AT&T
/	  All Rights Reserved

/	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
/	The copyright notice above does not evidence any
/	actual or intended publication of such source code.
	.file	"sbrk.s"

	.ident	"@(#)libc-i386:libc-i386/sys/sbrk.s	1.3"

#include <sys.s>

	.globl	sbrk
	.globl	brk
#ifdef SHLIB
	.globl	_libc_end
#endif

sbrk:
	MCOUNT			/ subroutine entry counter if profiling
	movl	4(%esp),%edx
	testl	%edx,%edx
	jz	.is_zero	/ We know the answer without asking
#ifdef SHLIB
	addl	_libc_end,%edx
#else
	addl	nd,%edx
#endif
	pushl	%edx
	call	brk
	addl	$4,%esp
	testl	%eax,%eax
	jnz	.brkerr
.is_zero:
#ifdef SHLIB
	movl	_libc_end,%eax
#else
	movl	nd,%eax
#endif
	subl	4(%esp),%eax
.brkerr:
	ret


/ brk(value)
/ as described in brk(2).
/ returns 0 for ok, -1 for error

	.globl	brk
	.globl	_cerror

brk:
	movl	$BRK,%eax
	lcall	SYSCALL
	jc	_cerror
	movl	4(%esp),%edx
#ifdef SHLIB
	movl	%edx,_libc_end
#else
	movl    %edx,nd
#endif
	xorl	%eax,%eax
	ret
#ifndef SHLIB
	.data
nd:
	.long	end
#endif
