#ifndef TOOLBOX_FILE_H
#define TOOLBOX_FILE_H

#include "cfileno.h"
#include "cshared.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

class cTBFile: public cTBFileNo {
private:
	const char *m_Filename;

protected:
	virtual ssize_t SysRead(void *Buffer, size_t Length);
	virtual ssize_t SysWrite(const void *Buffer, size_t Length);

public:
	cTBFile(void);
	virtual ~cTBFile();

	virtual bool Open(int Filed) { return cTBFileNo::Open(Filed); }
	virtual bool Open(const char *Filename, int Flags, 
			mode_t Mode = S_IRUSR + S_IWUSR);

	virtual bool Close(void);

	virtual bool Unlink(void) const;
	static  bool Unlink(const char *Filename);

	virtual bool IsOpen(void) const { return (FileNo() != -1); }
};

inline ssize_t cTBFile::SysRead(void *Buffer, size_t Length) {
	return ::read(FileNo(), Buffer, Length);
}

inline ssize_t cTBFile::SysWrite(const void *Buffer, size_t Length) {
	return ::write(FileNo(), Buffer, Length);
}


#endif // TOOLBOX_FILE_H
