1: #ifndef lint
   2: static char sccsid[] = "@(#)misc.c	4.2 (Berkeley) 7/7/83";
   3: #endif
   4: 
   5: #include <stdio.h>
   6: #include "courier.h"
   7: 
   8: Unspecified *
   9: Allocate(n)
  10:     LongCardinal n;
  11: {
  12:     Unspecified *p;
  13:     extern char *malloc();
  14: 
  15:     if (n > 100000) {
  16:         fprintf(stderr,
  17:             "Ridiculous request to memory allocator (%d words).\n",
  18:             n);
  19:         exit(1);
  20:     }
  21:     if (n == 0)
  22:         return (0);
  23:     p = (Unspecified *) malloc(n*sizeof(Unspecified));
  24:     if (p == 0) {
  25:         fprintf(stderr, "Out of memory.\n");
  26:         exit(1);
  27:     }
  28:     return (p);
  29: }
  30: 
  31: Deallocate(p)
  32:     Unspecified *p;
  33: {
  34:     if (p != 0)
  35:         free((char *) p);
  36: }
  37: 
  38: PackString(p, buf, flag)
  39:     String *p;
  40:     Unspecified *buf;
  41:     Boolean flag;
  42: {
  43:     Cardinal n;
  44: 
  45:     n = strlen(*p);
  46:     if (flag) {
  47:         PackCardinal(&n, buf, 1);
  48:         strncpy(buf+1, *p, n);
  49:     }
  50:     return (1 + n/2 + n%2);
  51: }
  52: 
  53: UnpackString(p, buf)
  54:     String *p;
  55:     Unspecified *buf;
  56: {
  57:     Cardinal n;
  58: 
  59:     UnpackCardinal(&n, buf);
  60:     *p = (String) Allocate(n/2 + 1);
  61:     buf++;
  62:     strncpy(*p, buf, n);
  63:     (*p)[n] = 0;
  64:     return (1 + n/2 + n%2);
  65: }

Defined functions

Deallocate defined in line 31; never used
PackString defined in line 38; used 1 times
UnpackString defined in line 53; never used

Defined variables

sccsid defined in line 2; never used
Last modified: 1983-07-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1062
Valid CSS Valid XHTML 1.0 Strict