Files
Digital-Research-Source-Code/CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/klib/sbrk.c
Sepp J Morris 31738079c4 Upload
Digital Research
2020-11-06 18:50:37 +01:00

41 lines
1.5 KiB
C

/****************************************************************************/
/* */
/* s b r k F u n c t i o n */
/* ------------------------- */
/* */
/* The "sbrk" function is used to allocate memory dynamically. */
/* */
/* Calling Sequence: */
/* */
/* addr = sbrk(incr); */
/* */
/* Where: */
/* incr Is the incremental number of bytes to be added to */
/* the program heap area. */
/* */
/* addr Is the beginning address of the allocated area. */
/* -1 is returned if allocation failed */
/* */
/****************************************************************************/
#include "stdio.h"
#include "cpm.h"
EXTERN BYTE *_break; /* Old break address */
/****************************/
BYTE *sbrk(incr) /* */
WORD incr; /* Incremental storage */
/* */
{ /****************************/
REG BYTE *t1; /* Temporary */
if(incr & 1) /* Disallow odd incr's */
incr++; /* Round up to next */
/* */
t1 = _break + incr; /* New break value */
/****************************/
if(brk(t1) == FAILURE) /* Allocate */
return(FAILURE); /* Can't */
/****************************/
t1 = _break; /* Save old break */
_break += incr; /* Set new break */
return(t1); /* And return */
} /****************************/