libutils/include/fs/CFile.hpp

62 lines
1.2 KiB
C++
Raw Permalink Normal View History

2017-10-29 09:24:06 +01:00
#ifndef CFILE_HPP_
#define CFILE_HPP_
#include <stdio.h>
#include <string>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <wut_types.h>
2017-10-29 09:24:06 +01:00
2018-03-11 16:44:04 +01:00
class CFile {
public:
enum eOpenTypes {
ReadOnly,
WriteOnly,
ReadWrite,
Append
};
CFile();
CFile(const std::string & filepath, eOpenTypes mode);
2018-06-20 14:44:30 +02:00
CFile(const uint8_t * memory, int32_t memsize);
2018-03-11 16:44:04 +01:00
virtual ~CFile();
2018-06-20 14:44:30 +02:00
int32_t open(const std::string & filepath, eOpenTypes mode);
int32_t open(const uint8_t * memory, int32_t memsize);
2018-03-11 16:44:04 +01:00
2018-06-20 14:44:30 +02:00
BOOL isOpen() const {
2018-03-11 16:44:04 +01:00
if(iFd >= 0)
return true;
if(mem_file)
return true;
return false;
}
void close();
2018-06-20 14:44:30 +02:00
int32_t read(uint8_t * ptr, size_t size);
int32_t write(const uint8_t * ptr, size_t size);
int32_t fwrite(const char *format, ...);
int32_t seek(long int offset, int32_t origin);
uint64_t tell() {
2018-03-11 16:44:04 +01:00
return pos;
};
2018-06-20 14:44:30 +02:00
uint64_t size() {
2018-03-11 16:44:04 +01:00
return filesize;
};
void rewind() {
this->seek(0, SEEK_SET);
};
protected:
2018-06-20 14:44:30 +02:00
int32_t iFd;
const uint8_t * mem_file;
uint64_t filesize;
uint64_t pos;
2017-10-29 09:24:06 +01:00
};
#endif