#include "mpg123.h"


int head_read(CFH c,u_int32_t *newhead)
{
  unsigned char hbuf[4];

  if(c->read(c,hbuf,4) != 4)
    return FALSE;

  *newhead = ((u_int32_t) hbuf[0] << 24) |
    ((u_int32_t) hbuf[1] << 16) |
    ((u_int32_t) hbuf[2] << 8)  |
    (u_int32_t) hbuf[3];

  return TRUE;
}


int skip_bytes(CFH c,int len)
{
        return c->seek(c,len,SEEK_CUR);
}

int head_shift(CFH c,u_int32_t *head)
{
  unsigned char hbuf;

  if(c->read(c,&hbuf,1) != 1)
    return 0;
  *head <<= 8;
  *head |= hbuf;
  *head &= 0xffffffff;
  return 1;
}

int read_frame_body(CFH c,unsigned char *buf, int size)
{
  int32_t l;

  if( (l=c->read(c,buf,size)) != size)
  {
    if(l <= 0)
      return 0;
    memset(buf+l,0,size-l);
  }

  return 1;
}

int back_bytes(CFH c,int bytes)
{
  if(c->seek(c,-bytes,SEEK_CUR) < 0)
    return -1;
  return 0;
}


