Initial revision
This commit is contained in:
59
modules/src/alloc/Malloc.c
Normal file
59
modules/src/alloc/Malloc.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/* M E M O R Y A L L O C A T I O N R O U T I N E S */
|
||||
|
||||
/* The memory allocation routines offered in this file are:
|
||||
|
||||
char *Malloc(n) : allocate n bytes
|
||||
char *Srealloc(ptr, n) : reallocate buffer to n bytes
|
||||
char *Salloc(str, n) : allocate n bytes, initialized with the string
|
||||
str
|
||||
|
||||
This file imports routines from "system".
|
||||
*/
|
||||
|
||||
#include <system.h>
|
||||
#include "in_all.h"
|
||||
#include "alloc.h"
|
||||
|
||||
PRIVATE
|
||||
m_fatal() {
|
||||
|
||||
(void) sys_write(2, "Out of memory\n", 14);
|
||||
sys_stop(S_EXIT);
|
||||
}
|
||||
|
||||
EXPORT char *
|
||||
Malloc(sz)
|
||||
unsigned int sz;
|
||||
{
|
||||
char *res = malloc(sz);
|
||||
|
||||
if (res == 0) m_fatal();
|
||||
return res;
|
||||
}
|
||||
|
||||
EXPORT char *
|
||||
Salloc(str, sz)
|
||||
register char str[];
|
||||
register unsigned int sz;
|
||||
{
|
||||
/* Salloc() is not a primitive function: it just allocates a
|
||||
piece of storage and copies a given string into it.
|
||||
*/
|
||||
char *res = malloc(sz);
|
||||
register char *m = res;
|
||||
|
||||
if (m == 0) m_fatal();
|
||||
while (sz--)
|
||||
*m++ = *str++;
|
||||
return res;
|
||||
}
|
||||
|
||||
EXPORT char *
|
||||
Srealloc(str, sz)
|
||||
char str[];
|
||||
unsigned int sz;
|
||||
{
|
||||
str = realloc(str, sz);
|
||||
if (str == 0) m_fatal();
|
||||
return str;
|
||||
}
|
||||
Reference in New Issue
Block a user