118537Sralph /* 2*23039Skre * Copyright (c) 1980 Regents of the University of California. 3*23039Skre * All rights reserved. The Berkeley software License Agreement 4*23039Skre * specifies the terms and conditions for redistribution. 518537Sralph * 6*23039Skre * @(#)malloc_.c 5.1 06/07/85 7*23039Skre */ 8*23039Skre 9*23039Skre /* 1018537Sralph * allows f77 programs to dynamicly allocate space 1118537Sralph * three routines: 1218537Sralph * call malloc(need, addr) 1318537Sralph * integer need, addr 1418537Sralph * 1518537Sralph * call free(addr) 1618537Sralph * integer addr 1718537Sralph * 1818537Sralph * call falloc( nelem, elsize, clean, basevec, addr, offset ) 1918537Sralph * integer nelem, elsize, clean, addr, offset 2018537Sralph * dimension basevec(1) 2118537Sralph * 2218537Sralph * malloc() & falloc() alloc space and put address in 'addr', 0 if can't 2318537Sralph * do it. free() frees a block. malloc() gets a block of at least 2418537Sralph * 'need' bytes; falloc() gets at least nelem*elsize bytes, zeros 2518537Sralph * the block if clean=1, and returns an offset so that the block 2618537Sralph * can be referenced as basevec(offset+1)...basevec(offset+nelem) 2718537Sralph * in the calling program. falloc() gets an extra element so that 2818537Sralph * all the elements will be in the block even if address arithmetic 2918537Sralph * involves truncation. 3018537Sralph */ 3118537Sralph 3218537Sralph char *calloc(), *malloc(); 3318537Sralph 3418537Sralph malloc_( need, addr ) 3518537Sralph int *need; char **addr; 3618537Sralph { 3718537Sralph *addr = malloc( *need ); 3818537Sralph } 3918537Sralph 4018537Sralph free_( addr ) 4118537Sralph char **addr; 4218537Sralph { 4318537Sralph free( *addr ); 4418537Sralph } 4518537Sralph 4618537Sralph falloc_( nelem, elsize, clean, basevec, addr, offset ) 4718537Sralph int *nelem, *elsize, *clean, *offset; 4818537Sralph char **addr, *basevec; 4918537Sralph { 5018537Sralph if( *clean == 1 ) 5118537Sralph *addr = calloc( *nelem + 1, *elsize ); 5218537Sralph else 5318537Sralph *addr = malloc( (*nelem + 1) * *elsize ); 5418537Sralph 5518537Sralph if( *addr != 0 ) 5618537Sralph *offset = ((*addr - basevec) / *elsize) + 1; 5718537Sralph else 5818537Sralph *offset = 0; 5918537Sralph 6018537Sralph } 61