1*47944Sbostic /*-
2*47944Sbostic * Copyright (c) 1980 The Regents of the University of California.
3*47944Sbostic * All rights reserved.
418537Sralph *
5*47944Sbostic * %sccs.include.proprietary.c%
623039Skre */
723039Skre
8*47944Sbostic #ifndef lint
9*47944Sbostic static char sccsid[] = "@(#)malloc_.c 5.2 (Berkeley) 04/12/91";
10*47944Sbostic #endif /* not lint */
11*47944Sbostic
1223039Skre /*
1318537Sralph * allows f77 programs to dynamicly allocate space
1418537Sralph * three routines:
1518537Sralph * call malloc(need, addr)
1618537Sralph * integer need, addr
1718537Sralph *
1818537Sralph * call free(addr)
1918537Sralph * integer addr
2018537Sralph *
2118537Sralph * call falloc( nelem, elsize, clean, basevec, addr, offset )
2218537Sralph * integer nelem, elsize, clean, addr, offset
2318537Sralph * dimension basevec(1)
2418537Sralph *
2518537Sralph * malloc() & falloc() alloc space and put address in 'addr', 0 if can't
2618537Sralph * do it. free() frees a block. malloc() gets a block of at least
2718537Sralph * 'need' bytes; falloc() gets at least nelem*elsize bytes, zeros
2818537Sralph * the block if clean=1, and returns an offset so that the block
2918537Sralph * can be referenced as basevec(offset+1)...basevec(offset+nelem)
3018537Sralph * in the calling program. falloc() gets an extra element so that
3118537Sralph * all the elements will be in the block even if address arithmetic
3218537Sralph * involves truncation.
3318537Sralph */
3418537Sralph
3518537Sralph char *calloc(), *malloc();
3618537Sralph
malloc_(need,addr)3718537Sralph malloc_( need, addr )
3818537Sralph int *need; char **addr;
3918537Sralph {
4018537Sralph *addr = malloc( *need );
4118537Sralph }
4218537Sralph
free_(addr)4318537Sralph free_( addr )
4418537Sralph char **addr;
4518537Sralph {
4618537Sralph free( *addr );
4718537Sralph }
4818537Sralph
falloc_(nelem,elsize,clean,basevec,addr,offset)4918537Sralph falloc_( nelem, elsize, clean, basevec, addr, offset )
5018537Sralph int *nelem, *elsize, *clean, *offset;
5118537Sralph char **addr, *basevec;
5218537Sralph {
5318537Sralph if( *clean == 1 )
5418537Sralph *addr = calloc( *nelem + 1, *elsize );
5518537Sralph else
5618537Sralph *addr = malloc( (*nelem + 1) * *elsize );
5718537Sralph
5818537Sralph if( *addr != 0 )
5918537Sralph *offset = ((*addr - basevec) / *elsize) + 1;
6018537Sralph else
6118537Sralph *offset = 0;
6218537Sralph
6318537Sralph }
64