Makefile
Malloc.c
+Srealloc.c
+Realloc.c
+Salloc.c
alloc.3
alloc.h
botch.c
CFLAGS = -O $(INCLUDES)
CSRC = Malloc.c\
+ Salloc.c\
+ Srealloc.c\
+ Realloc.c\
botch.c\
clear.c\
st_alloc.c\
SOURCES = alloc.h\
$(CSRC)
-OBJECTS = botch.o clear.o st_alloc.o Malloc.o std_alloc.o No_Mem.o
+OBJECTS = botch.o clear.o st_alloc.o Malloc.o Salloc.o \
+ Srealloc.o Realloc.o std_alloc.o No_Mem.o
all: liballoc.a
/* 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".
*/
if (res == 0) No_Mem();
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) No_Mem();
- while (sz--)
- *m++ = *str++;
- return res;
-}
-
-EXPORT char *
-Srealloc(str, sz)
- char str[];
- unsigned int sz;
-{
- str = realloc(str, sz);
- if (str == 0) No_Mem();
- return str;
-}
--- /dev/null
+/* $Header$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* 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 *Realloc(ptr, n) : reallocate buffer to n bytes
+
+ This file imports routines from "system".
+*/
+
+#include <system.h>
+#include "in_all.h"
+#include "alloc.h"
+
+EXPORT char *
+Realloc(ptr, sz)
+ char ptr[];
+ unsigned int sz;
+{
+ ptr = realloc(ptr, sz);
+ if (ptr == 0) No_Mem();
+ return ptr;
+}
--- /dev/null
+/* $Header$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* 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 *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"
+
+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) No_Mem();
+ while (sz--)
+ *m++ = *str++;
+ return res;
+}
--- /dev/null
+/* $Header$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* 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 *Srealloc(ptr, n) : reallocate buffer to n bytes
+
+ This file imports routines from "system".
+*/
+
+#include <system.h>
+#include "in_all.h"
+#include "alloc.h"
+
+EXPORT char *
+Srealloc(str, sz)
+ char str[];
+ unsigned int sz;
+{
+ return Realloc(str, sz);
+}
.TH ALLOC 3ACK "March 25, 1986"
.ad
.SH NAME
-Malloc, Salloc, Srealloc, st_alloc, st_free\ \-\ low level memory allocation routines
+Malloc, Salloc, Realloc, Srealloc, st_alloc, st_free\ \-\ low level memory allocation routines
.SH SYNOPSIS
.B #include <alloc.h>
.PP
.B char *str;
.B unsigned int size;
.PP
+.B char *Realloc(ptr, size)
+.B char *buf;
+.B unsigned int size;
+.PP
.B char *Srealloc(str, size)
.br
.B char *str;
.br
.B unsigned int size;
.PP
+.br
+.B clear(ptr, size)
+.br
+.B char *ptr;
+.br
+.B unsigned int size;
+.PP
.SH DESCRIPTION
This set of routines provides a checking memory allocation mechanism.
.PP
\fISalloc\fR returns a pointer to a block of at least \fIsize\fR
bytes, initialized with the null-terminated string \fIstr\fR.
.PP
+\fIRealloc\fR changes the size of
+the block at \fIbuf\fR to \fIsize\fR bytes, and returns a pointer to the
+(possibly moved) block.
+.PP
\fISrealloc\fR reallocates
the string at \fIstr\fR to \fIsize\fR bytes.
+It actually does the same as \fIRealloc\fP, and exists only for
+backwards compatibility.
.PP
All these routines use \fImalloc\fR and \fIrealloc\fR.
\fIFree\fR can be used on pointers returned by these routines.
containing the head of the free list, and \fIsize\fR again contains the size
of the structures.
These last two routines are best used in a macro.
+.PP
+\fIClear\fR clears \fIsize\fR bytes, starting at \fIptr\fR.
.SH FILES
.nf
~em/modules/h/alloc.h
.SH "SEE ALSO"
malloc(3)
.SH DIAGNOSTICS
-\fIMalloc\fR, \fISalloc\fR, \fISrealloc\fR, and \fIst_alloc\fR
+\fIMalloc\fR, \fISalloc\fR, \fIRealloc\fP, \fISrealloc\fR, and \fIst_alloc\fR
call a routine \fINo_Mem\fR if there is no memory available. This routine
is not supposed to return. A default one, that
gives an error message and stops execution, is provided.
char *Malloc(n) allocate n bytes
char *Salloc(str, n) allocate n bytes and fill them with
string str
- char *Realloc(str, n) reallocate the string at str to n bytes,
- only works if str was last allocated
+ char *Realloc(str, n) reallocate the block at str to n bytes.
+ char *Srealloc(str, n) same as Realloc.
*/
-extern char *Salloc(), *Malloc(), *Srealloc();
+extern char *Salloc(), *Malloc(), *Srealloc(), *Realloc();
extern char *malloc(), *realloc();
/* S T R U C T U R E - S T O R A G E D E F I N I T I O N S */