diff --git a/modules/src/alloc/.distr b/modules/src/alloc/.distr index 7b89927e1..98413aacc 100644 --- a/modules/src/alloc/.distr +++ b/modules/src/alloc/.distr @@ -1,5 +1,8 @@ Makefile Malloc.c +Srealloc.c +Realloc.c +Salloc.c alloc.3 alloc.h botch.c diff --git a/modules/src/alloc/Makefile b/modules/src/alloc/Makefile index 7c0e1ff0b..de720ea75 100644 --- a/modules/src/alloc/Makefile +++ b/modules/src/alloc/Makefile @@ -7,6 +7,9 @@ INCLUDES = -I. -I$(HDIR) CFLAGS = -O $(INCLUDES) CSRC = Malloc.c\ + Salloc.c\ + Srealloc.c\ + Realloc.c\ botch.c\ clear.c\ st_alloc.c\ @@ -15,7 +18,8 @@ CSRC = Malloc.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 diff --git a/modules/src/alloc/Malloc.c b/modules/src/alloc/Malloc.c index 756c00b6f..19dba1c07 100644 --- a/modules/src/alloc/Malloc.c +++ b/modules/src/alloc/Malloc.c @@ -8,9 +8,6 @@ /* 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". */ @@ -28,30 +25,3 @@ Malloc(sz) 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; -} diff --git a/modules/src/alloc/Realloc.c b/modules/src/alloc/Realloc.c new file mode 100644 index 000000000..6c477539e --- /dev/null +++ b/modules/src/alloc/Realloc.c @@ -0,0 +1,27 @@ +/* $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 +#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; +} diff --git a/modules/src/alloc/Salloc.c b/modules/src/alloc/Salloc.c new file mode 100644 index 000000000..b24908635 --- /dev/null +++ b/modules/src/alloc/Salloc.c @@ -0,0 +1,35 @@ +/* $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 +#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; +} diff --git a/modules/src/alloc/Srealloc.c b/modules/src/alloc/Srealloc.c new file mode 100644 index 000000000..9f1fede3c --- /dev/null +++ b/modules/src/alloc/Srealloc.c @@ -0,0 +1,25 @@ +/* $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 +#include "in_all.h" +#include "alloc.h" + +EXPORT char * +Srealloc(str, sz) + char str[]; + unsigned int sz; +{ + return Realloc(str, sz); +} diff --git a/modules/src/alloc/alloc.3 b/modules/src/alloc/alloc.3 index f9a4f6186..7eac028ec 100644 --- a/modules/src/alloc/alloc.3 +++ b/modules/src/alloc/alloc.3 @@ -1,7 +1,7 @@ .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 .PP @@ -14,6 +14,10 @@ Malloc, Salloc, Srealloc, st_alloc, st_free\ \-\ low level memory allocation rou .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; @@ -34,6 +38,13 @@ Malloc, Salloc, Srealloc, st_alloc, st_free\ \-\ low level memory allocation rou .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 @@ -43,8 +54,14 @@ bytes, beginning on a boundary suitable for any data type. \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. @@ -62,6 +79,8 @@ the structure to be freed, \fIphead\fR is again a pointer to a field 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 @@ -70,7 +89,7 @@ These last two routines are best used in a macro. .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. diff --git a/modules/src/alloc/alloc.h b/modules/src/alloc/alloc.h index 5c3018493..09916a0d4 100644 --- a/modules/src/alloc/alloc.h +++ b/modules/src/alloc/alloc.h @@ -11,11 +11,11 @@ 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 */