libgui/source/fs/CFile.hpp

72 lines
1.2 KiB
C++
Raw Normal View History

2019-08-14 23:24:55 +02: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>
class CFile {
public:
enum eOpenTypes {
ReadOnly,
WriteOnly,
ReadWrite,
Append
};
CFile();
2020-08-13 12:38:07 +02:00
CFile(const std::string &filepath, eOpenTypes mode);
CFile(const uint8_t *memory, int32_t memsize);
2019-08-14 23:24:55 +02:00
virtual ~CFile();
2020-08-13 12:38:07 +02:00
int32_t open(const std::string &filepath, eOpenTypes mode);
int32_t open(const uint8_t *memory, int32_t memsize);
2019-08-14 23:24:55 +02:00
BOOL isOpen() const {
2020-08-13 12:38:07 +02:00
if (iFd >= 0)
2019-08-14 23:24:55 +02:00
return true;
2020-08-13 12:38:07 +02:00
if (mem_file)
2019-08-14 23:24:55 +02:00
return true;
return false;
}
void close();
2020-08-13 12:38:07 +02:00
int32_t read(uint8_t *ptr, size_t size);
int32_t write(const uint8_t *ptr, size_t size);
2019-08-14 23:24:55 +02:00
int32_t fwrite(const char *format, ...);
2020-08-13 12:38:07 +02:00
2019-08-14 23:24:55 +02:00
int32_t seek(long int offset, int32_t origin);
2020-08-13 12:38:07 +02:00
2019-08-14 23:24:55 +02:00
uint64_t tell() {
return pos;
};
2020-08-13 12:38:07 +02:00
2019-08-14 23:24:55 +02:00
uint64_t size() {
return filesize;
};
2020-08-13 12:38:07 +02:00
2019-08-14 23:24:55 +02:00
void rewind() {
this->seek(0, SEEK_SET);
};
protected:
int32_t iFd;
2020-08-13 12:38:07 +02:00
const uint8_t *mem_file;
2019-08-14 23:24:55 +02:00
uint64_t filesize;
uint64_t pos;
};
#endif