1: /*
   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.
   5:  *
   6:  *	@(#)malloc_.c	5.1	6/7/85
   7:  */
   8: 
   9: /*
  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: 
  32: char *calloc(), *malloc();
  33: 
  34: malloc_( need, addr )
  35: int *need; char **addr;
  36: {
  37:     *addr = malloc( *need );
  38: }
  39: 
  40: free_( addr )
  41: char **addr;
  42: {
  43:     free( *addr );
  44: }
  45: 
  46: falloc_( nelem, elsize, clean, basevec, addr, offset )
  47: int *nelem, *elsize, *clean, *offset;
  48: char **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: }

Defined functions

falloc_ defined in line 46; never used
free_ defined in line 40; never used
malloc_ defined in line 34; never used
Last modified: 1987-02-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 486
Valid CSS Valid XHTML 1.0 Strict