WUMSLoader/source/fs/CFile.hpp

72 lines
1.2 KiB
C++
Raw Normal View History

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