//------------------------------------------------------------------------------
//	File:					binfile.h
//	Date:					4/10/99
//	Author:				Chris Phillips
//
//	Description:
//
//------------------------------------------------------------------------------


#ifndef binfile_h
#define binfile_h

#include "buffer.h"

//------------------------------------------------------------------------------
//	enums
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//	classes
//------------------------------------------------------------------------------


class Binfile{
private:
	FILE *file;
	unsigned int file_size;
	bool valid;

	Binfile();

public:

	Binfile(char *name)
	{
		file=fopen(name,"rb");
		if(file==NULL)
			{
			valid=FALSE;
			return;
			}
		fseek(file,0,SEEK_END);
		file_size=ftell(file);
		fseek(file,0,SEEK_SET);
		valid=TRUE;
	}
	~Binfile()
		{
		close();
		}
	void close()
		{
		if(file!=NULL)
			fclose(file);
		valid=FALSE;
		}
	bool test()
		{
		if(valid)
			return(TRUE);
		return(FALSE);
		}
	unsigned int size(){return (file_size);}
	unsigned int read(char *buf,unsigned int num)
		{
		if(!valid || size==0)
			return(0);
		return(fread(buf,num,sizeof(char),file));
		}
	unsigned int read(char *buf)
		{
      return(fread(buf,sizeof(char),file_size,file));
		}
	word read_word()
		{
		word w;
      fread(&w,sizeof(word),1,file);
		return(w);
		}
	long read_long()
		{
		long l;
      fread(&l,sizeof(long),1,file);
		return(l);
		}
	unsigned int tell()
		{
		return( ftell(file) );
		}
	void seek(unsigned int pos)
		{
		fseek(file,pos,SEEK_SET);
		}
};

#endif binfile_h	

