diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-25 20:17:53 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-25 20:17:53 +0100 |
| commit | 3b3b36dcc6542e203475fe1d50ed89799e3f3fc6 (patch) | |
| tree | 3d1e4cfba79343e2b5ef8db58c58271009a44937 /Public/Developer/System.Core/Headers/File.hxx | |
| parent | d968190d1ba48638c1481be0d367ee3cea82ae55 (diff) | |
Kernel: implement some tickets, improved stuff.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Public/Developer/System.Core/Headers/File.hxx')
| -rw-r--r-- | Public/Developer/System.Core/Headers/File.hxx | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/Public/Developer/System.Core/Headers/File.hxx b/Public/Developer/System.Core/Headers/File.hxx new file mode 100644 index 00000000..06c2a22e --- /dev/null +++ b/Public/Developer/System.Core/Headers/File.hxx @@ -0,0 +1,105 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#ifndef __FILE_API__ +#define __FILE_API__ + +#include <System.Core/Headers/Defines.hxx> + +namespace System { +class FileInterface; +class DirectoryInterface; + +typedef IntPtrType SymlinkType; +typedef IntPtrType FileType; +typedef IntPtrType DirectoryType; +typedef IntPtrType FSRef; + +enum { + kErrorNoSuchPath = -44, + kErrorNotAFile = -45, + kErrorNotADirectory = -46, + kErrorDirectory = -47, + kErrorBrokenSymlink = -48, +}; + +/// @brief System file interface + +class FileInterface final { + public: + explicit FileInterface(const char *path) { + mHandle = kApplicationObject->Invoke(kApplicationObject, kProcessCallOpenHandle, + 0, path); + } + + ~FileInterface() { + kApplicationObject->Invoke(kApplicationObject, kProcessCallCloseHandle, 0, + mHandle); + } + + public: + CA_COPY_DEFAULT(FileInterface); + + public: + PtrVoidType Read(UIntPtrType off, SizeType sz) { + return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, 2, + off, sz); + } + PtrVoidType Read(SizeType sz) { + return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, 3, + sz); + } + + void Write(PtrVoidType buf, UIntPtrType off, SizeType sz) { + kApplicationObject->Invoke(kApplicationObject, mHandle, 4, buf, off, sz); + } + void Write(PtrVoidType buf, SizeType sz) { + kApplicationObject->Invoke(kApplicationObject, mHandle, 5, buf, sz); + } + + void Seek(UIntPtrType off) { + kApplicationObject->Invoke(kApplicationObject, mHandle, 5); + } + void Rewind() { kApplicationObject->Invoke(kApplicationObject, mHandle, 6); } + + public: + const char *MIME(); + void MIME(const char *mime); + + private: + FileType mHandle; +}; + +typedef FileInterface *FilePtr; + +/// @brief file exception +/// Throws when the file isn't found or invalid. +class FileException : public SystemException { + public: + explicit FileException() = default; + virtual ~FileException() = default; + + public: + CA_COPY_DEFAULT(FileException); + + public: + const char *Name() override { return "FileException"; } + const char *Reason() override { return mReason; } + + private: + const char *mReason{"System.Core: FileException: Catastrophic failure!"}; +}; + +inline IntPtrType MakeSymlink(const char *from, const char *outputWhere) { + CA_MUST_PASS(from); + CA_MUST_PASS(outputWhere); + + return kApplicationObject->Invoke(kApplicationObject, kProcessCallOpenHandle, 1, + from); +} +} // namespace System + +#endif // ifndef __FILE_API__ |
