#include <stdio.h>

#ifdef ferror
# undef ferror
# undef feof
#endif
/* Linux defines these as macros, which messes up the class definition. */
# define _stdio_ferror ferror
# define _stdio_feof feof

struct rbfile	{
	private:
	char *buf;	/* The start of the buffer.  Buffer starts at BOF. */
	char *ptr;	/* The current position in the buffer. */
	char *end;	/* The highest spot in the buffer that contains data.*/
	char *endalloc;	/* The end of the buffer. */
	char *eof;	/* The end of the file. */
	FILE *fp;
	const static int BS;
	int delayed_remove;
	void grow(int n);
	void remove_buf();
	int (rbfile::*fg)();
	int fgetc_eof(), fgetc_direct(), fgetc_end(), fgetc_buf();

	rbfile(const rbfile&);
	rbfile& operator=(const rbfile&);

	public:
	void commit();		/* End buffering. */
	void rewind();		/* Back to beginning */
	int fgetc()	{ return (this->*fg)(); }
	char *fgets(char *b, int sz);
	int fread(void *p, size_t sz, int n);
	rbfile(FILE *fp);
	~rbfile()	{delete [] buf;}
	long tell() const;
	int ungetc(int c);
	int ferror() const {return ::_stdio_ferror(fp);}
	int feof() const;
	};

typedef rbfile RBFILE;
