/*  pl-buffer.c,v 1.1 1993/04/26 13:51:12 jan Exp

    Part of XPCE
    Designed and implemented by Anjo Anjewierden and Jan Wielemaker
    E-mail: jan@swi.psy.uva.nl

    Copyright (C) 1993 University of Amsterdam. All rights reserved.
*/

#include "pl-incl.h"
#include "pl-buffer.h"

Buffer
newBuffer()
{ Buffer b = allocHeap(sizeof(buffer));
  
  initBuffer(b);
  return b;
}


void
freeBuffer(b)
Buffer b;
{ discardBuffer(b);
  freeHeap(b, sizeof(buffer));
}


void
growBuffer(b, minfree)
Buffer b;
long minfree;
{ long sz = b->max - b->base;
  long top = b->top - b->base;

  sz = (sz ? ROUND((sz * 3) / 2, 512) : 512);

  b->base = (b->base ? realloc(b->base, sz) : malloc(sz));
  if ( !b->base )
    fatalError("Not enough memory");

  b->top = b->base + top;
  b->max = b->base + sz;
}
