/*->c.buffer */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "os.h"


#include "h.fsx"


#include "h.buffer"



#define HSIZE 4

#define ESC 27

/*
  ESC
  B
  0
  0
  length    word

  size 4 bytes
*/



os_error * bf_dump(buffer * b)
{
 os_error * ep;

 b->data[0]=ESC;
 b->data[1]='B';
 b->data[2]=(b->p & 0xFF);
 b->data[3]=((b->p)>>8) & 0xFF;

 ep=fs_write(b->fh,b->data,b->p);
 b->length+=b->p;

 b->p=HSIZE;

 return(ep);
}



os_error * bf_put(buffer * b,int c)
{
 os_error * ep;

 ep=NULL;

 if(b->p<b->size) b->data[b->p++]=c;
 else
 {
  ep=bf_dump(b);
  if(b->p<b->size) b->data[b->p++]=c;
 }

 return(ep);
}




os_error * bf_alloc(buffer * b,int size,int fh,int length)
{
 os_error * ep;

 b->fh=fh;
 b->p=HSIZE;
 b->length=length;
 b->end=0;
 b->size=size;

 ep=NULL;

 return(ep);
}


os_error * bf_dealloc(buffer * b)
{
 os_error * ep;

 ep=NULL;

 return(ep);
}


