mirror of
https://github.com/Maschell/libutils.git
synced 2024-11-05 20:55:08 +01:00
58 lines
1.0 KiB
C++
58 lines
1.0 KiB
C++
|
#ifndef CFILE_HPP_
|
||
|
#define CFILE_HPP_
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <string>
|
||
|
#include <string.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <dynamic_libs/os_types.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
class CFile
|
||
|
{
|
||
|
public:
|
||
|
enum eOpenTypes
|
||
|
{
|
||
|
ReadOnly,
|
||
|
WriteOnly,
|
||
|
ReadWrite,
|
||
|
Append
|
||
|
};
|
||
|
|
||
|
CFile();
|
||
|
CFile(const std::string & filepath, eOpenTypes mode);
|
||
|
CFile(const u8 * memory, s32 memsize);
|
||
|
virtual ~CFile();
|
||
|
|
||
|
s32 open(const std::string & filepath, eOpenTypes mode);
|
||
|
s32 open(const u8 * memory, s32 memsize);
|
||
|
|
||
|
bool isOpen() const {
|
||
|
if(iFd >= 0)
|
||
|
return true;
|
||
|
|
||
|
if(mem_file)
|
||
|
return true;
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
void close();
|
||
|
|
||
|
s32 read(u8 * ptr, size_t size);
|
||
|
s32 write(const u8 * ptr, size_t size);
|
||
|
s32 fwrite(const char *format, ...);
|
||
|
s32 seek(long int offset, s32 origin);
|
||
|
u64 tell() { return pos; };
|
||
|
u64 size() { return filesize; };
|
||
|
void rewind() { this->seek(0, SEEK_SET); };
|
||
|
|
||
|
protected:
|
||
|
s32 iFd;
|
||
|
const u8 * mem_file;
|
||
|
u64 filesize;
|
||
|
u64 pos;
|
||
|
};
|
||
|
|
||
|
#endif
|