1 /*- 2 * Copyright (c) 1980 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)malloc_.c 5.2 (Berkeley) 04/12/91"; 10 #endif /* not lint */ 11 12 /* 13 * allows f77 programs to dynamicly allocate space 14 * three routines: 15 * call malloc(need, addr) 16 * integer need, addr 17 * 18 * call free(addr) 19 * integer addr 20 * 21 * call falloc( nelem, elsize, clean, basevec, addr, offset ) 22 * integer nelem, elsize, clean, addr, offset 23 * dimension basevec(1) 24 * 25 * malloc() & falloc() alloc space and put address in 'addr', 0 if can't 26 * do it. free() frees a block. malloc() gets a block of at least 27 * 'need' bytes; falloc() gets at least nelem*elsize bytes, zeros 28 * the block if clean=1, and returns an offset so that the block 29 * can be referenced as basevec(offset+1)...basevec(offset+nelem) 30 * in the calling program. falloc() gets an extra element so that 31 * all the elements will be in the block even if address arithmetic 32 * involves truncation. 33 */ 34 35 char *calloc(), *malloc(); 36 37 malloc_( need, addr ) 38 int *need; char **addr; 39 { 40 *addr = malloc( *need ); 41 } 42 43 free_( addr ) 44 char **addr; 45 { 46 free( *addr ); 47 } 48 49 falloc_( nelem, elsize, clean, basevec, addr, offset ) 50 int *nelem, *elsize, *clean, *offset; 51 char **addr, *basevec; 52 { 53 if( *clean == 1 ) 54 *addr = calloc( *nelem + 1, *elsize ); 55 else 56 *addr = malloc( (*nelem + 1) * *elsize ); 57 58 if( *addr != 0 ) 59 *offset = ((*addr - basevec) / *elsize) + 1; 60 else 61 *offset = 0; 62 63 } 64