1: # include   <sccs.h>
   2: 
   3: SCCSID(@(#)nalloc.c	8.1	12/31/84)
   4: 
   5: 
   6: /*
   7: **	NALLOC --
   8: **		Dynamic allocation routine which
   9: ** 		merely calls alloc(III), returning
  10: **		0 if no core and a pointer otherwise.
  11: **
  12: */
  13: 
  14: char *nalloc(s)
  15: int s;
  16: {
  17: #	ifdef PDP11
  18:     unsigned    size;
  19: 
  20:     size = s;
  21:     size = alloc(size);
  22:     if (size == -1)
  23:         return (0);
  24:     return (size);
  25: 
  26: #	else
  27:     extern char *malloc();
  28: 
  29:     return (malloc(s));
  30: #	endif
  31: }
  32: /*
  33: **	SALLOC -- allocate
  34: **		place for string and initialize it,
  35: **		return string or 0 if no core.
  36: **
  37: */
  38: 
  39: char *salloc(s)
  40: char        *s;
  41: {
  42:     register unsigned   i;
  43:     register char       *string;
  44:     char            *malloc();
  45: 
  46:     string = s;
  47: #	ifdef PDP11
  48:     i = alloc(length(string) + 1);
  49:     if (i == -1)
  50:         return (0);
  51: #	else
  52:     i = (unsigned)malloc(length(string) + 1);
  53: #	endif
  54: 
  55:     if (i)
  56:         smove(string, i);
  57:     return ((char *)i);
  58: }
  59: 
  60: /*
  61: **	XFREE -- Free possibly dynamic storage
  62: **		checking if its in the heap first.
  63: **
  64: **		0 - freed
  65: **		1 - not in heap
  66: **
  67: */
  68: 
  69: xfree(cp)
  70: char        *cp;
  71: {
  72:     extern          end;    /* break (II) */
  73:     register char       *lcp, *lend, *lacp;
  74: 
  75:     lcp = cp;
  76:     lacp = (char *)&cp;
  77:     lend = (char *)&end;
  78:     if (lcp >= lend && lcp < lacp)  /* make sure its in heap */
  79:     {
  80:         free(lcp);
  81:         return (0);
  82:     }
  83:     return (1);
  84: }
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1031
Valid CSS Valid XHTML 1.0 Strict