This is mymalloc.c in view mode; [Download] [Up]
/*
* mymalloc.c of dviamiga software package.
*/
#include "structures.h"
/*
* External variables we access
*/
extern TeXfontdesctype *TeXfonts[] ;
extern fontdesctype *fontlist ;
extern struct fontdesctype *curfnt ;
/*
* Functions we use.
*/
extern void *malloc() ;
extern void error() ;
extern void exit() ;
extern void freetemp() ;
extern void free() ;
extern void fontinit() ;
extern void freepages() ;
/*
* Our own memory clear routine.
*/
void clearmem(p, size)
register long *p ;
register int size ;
{
while (size >= sizeof(long)) {
*p++ = 0 ;
size -= sizeof(long) ;
}
while (size > 0) {
size-- ;
((char *)p)[size] = 0 ;
}
}
/*
* We also need to be able to copy memory.
*/
void movmem(src, dest, size)
register long *src, *dest, size ;
{
while (size >= sizeof(long)) {
*dest++ = *src++ ;
size -= sizeof(long) ;
}
while (size > 0) {
size-- ;
((char *)dest)[size] = ((char *)src)[size] ;
}
}
/*
* We also need to be able to copy memory.
*/
void cmpmem(src, dest, size)
register long *src, *dest, size ;
{
while (size > sizeof(long)) {
*dest++ = ~*src++ ;
size -= sizeof(long) ;
}
while (size > 0) {
size-- ;
((char *)dest)[size] = ~((char *)src)[size] ;
}
}
/*
* This routine allocates memory of the specific type. If the allocation
* fails, we try to free memory by deleting some fonts.
*/
void *mymalloc(size, type)
int size ;
long type ;
{
register void *p ;
p = malloc(size) ;
if (p==NULL)
error("! could not allocate memory") ;
if (type & MEMF_CLEAR)
clearmem(p, size) ;
return(p) ;
}
/*
* Some tempbuf routines.
*/
static void *tmpbuf = NULL ;
static long csize = 0L ;
void *tempbuf(size)
long size ;
{
if (size > csize) {
freetemp() ;
tmpbuf = mymalloc((int)size, MEMF_CLEAR) ;
csize = size ;
} else
clearmem(tmpbuf, size) ;
return(tmpbuf) ;
}
/*
* Frees the tempbuf.
*/
void
freetemp() {
if (tmpbuf != NULL) {
free(tmpbuf) ;
tmpbuf = NULL ;
csize = 0 ;
}
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.