BSD 4_3 release
[unix-history] / usr / src / usr.lib / libU77 / malloc_.c
CommitLineData
b43e8089 1/*
161423a6
RE
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
b43e8089 5 *
95f51977 6 * @(#)malloc_.c 5.1 6/7/85
161423a6
RE
7 */
8
9/*
b43e8089
RC
10 * allows f77 programs to dynamicly allocate space
11 * three routines:
12 * call malloc(need, addr)
13 * integer need, addr
14 *
15 * call free(addr)
16 * integer addr
17 *
18 * call falloc( nelem, elsize, clean, basevec, addr, offset )
19 * integer nelem, elsize, clean, addr, offset
20 * dimension basevec(1)
21 *
22 * malloc() & falloc() alloc space and put address in 'addr', 0 if can't
23 * do it. free() frees a block. malloc() gets a block of at least
24 * 'need' bytes; falloc() gets at least nelem*elsize bytes, zeros
25 * the block if clean=1, and returns an offset so that the block
26 * can be referenced as basevec(offset+1)...basevec(offset+nelem)
27 * in the calling program. falloc() gets an extra element so that
28 * all the elements will be in the block even if address arithmetic
29 * involves truncation.
30 */
31
32char *calloc(), *malloc();
33
34malloc_( need, addr )
35int *need; char **addr;
36{
37 *addr = malloc( *need );
38}
39
40free_( addr )
41char **addr;
42{
43 free( *addr );
44}
45
46falloc_( nelem, elsize, clean, basevec, addr, offset )
47int *nelem, *elsize, *clean, *offset;
48char **addr, *basevec;
49{
50 if( *clean == 1 )
51 *addr = calloc( *nelem + 1, *elsize );
52 else
53 *addr = malloc( (*nelem + 1) * *elsize );
54
55 if( *addr != 0 )
56 *offset = ((*addr - basevec) / *elsize) + 1;
57 else
58 *offset = 0;
59
60}