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