1
2
3
4
5
6 #ifndef CMAJOR_RT_IO_INCLUDED
7 #define CMAJOR_RT_IO_INCLUDED
8 #include <cmajor/rt/RtApi.hpp>
9 #include <stdexcept>
10 #include <stdint.h>
11
12 const int stdInFileHandle = 0;
13 const int stdOutFileHandle = 1;
14 const int stdErrFileHandle = 2;
15
16 enum class OpenMode : uint8_t
17 {
18 none= 0,
19 read= 1 << 0,
20 write= 1 << 1,
21 append= 1 << 2,
22 binary= 1 << 3
23 };
24
25 enum class Origin : uint8_t
26 {
27 seekSet, seekCur, seekEnd
28 };
29
30 inline OpenMode operator&(OpenMode left, OpenMode right)
31 {
32 return OpenMode(uint8_t(left) & uint8_t(right));
33 }
34
35 inline OpenMode operator|(OpenMode left, OpenMode right)
36 {
37 return OpenMode(uint8_t(left) | uint8_t(right));
38 }
39
40 extern "C" void* RtOpen(const char* filePath, OpenMode openMode, int32_t& errorStringHandle);
41 extern "C" void* RtOpenStdFile(int handle, int32_t& errorStringHandle);
42 extern "C" bool RtClose(void* fileHandle, int32_t& errorStringHandle);
43 extern "C" bool RtDisposeFile(void* fileHandle, int32_t& errorStringHandle);
44 extern "C" int64_t RtWrite(void* fileHandle, const uint8_t* buffer, int64_t count, int32_t& errorStringHandle);
45 extern "C" bool RtWriteByte(void* fileHandle, uint8_t x, int32_t& errorStringHandle);
46 extern "C" int64_t RtRead(void* fileHandle, uint8_t* buffer, int64_t bufferSize, int32_t& errorStringHandle);
47 extern "C" int32_t RtReadByte(void* fileHandle);
48 extern "C" bool RtEof(void* fileHandle);
49 extern "C" bool RtGetFileError(void* fileHandle, int32_t& errorStringHandle);
50 extern "C" bool RtSeek(void* fileHandle, int64_t pos, Origin origin, int32_t& errorStringHandle);
51 extern "C" int64_t RtTell(void* fileHandle, int32_t& errorStringHandle);
52 extern "C" bool RtFlush(void* fileHandle, int32_t& errorStringHandle);
53 extern "C" bool RtFileExists(const char* filePath);
54 extern "C" bool RtLastWriteTimeLess(const char* filePath1, const char* filePath2);
55 extern "C" int64_t RtGetFileSize(const char* filePath, int32_t& errorStringHandle);
56 extern "C" bool RtRemoveFile(const char* filePath, int32_t& errorStringHandle);
57 extern "C" bool RtCopyFile(const char* sourceFilePath, const char* targetFilePath, int32_t& errorStringHandle);
58 extern "C" bool RtMoveFile(const char* sourceFilePath, const char* targetFilePath, int32_t & errorStringHandle);
59 extern "C" bool RtIsConsoleHandle(int handle);
60
61 extern "C" void InitIo();
62 extern "C" void DoneIo();
63
64 #endif // CMAJOR_RT_IO_INCLUDED