summaryrefslogtreecommitdiffhomepage
path: root/SDK/Libraries/CoreSystem/Sources/File.c
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-05-27 20:45:46 +0200
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-05-27 20:45:46 +0200
commit9db58da40cfcb6643412bfae25aefc0cd1077f9d (patch)
treec6664fc649968ca1be7ddc59dfe3e9a7dd0f3ebc /SDK/Libraries/CoreSystem/Sources/File.c
parentce84bea215424ff36a2c18cab67835edfa8f71b5 (diff)
MHR-23: Improve project structure, make it better.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'SDK/Libraries/CoreSystem/Sources/File.c')
-rw-r--r--SDK/Libraries/CoreSystem/Sources/File.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/SDK/Libraries/CoreSystem/Sources/File.c b/SDK/Libraries/CoreSystem/Sources/File.c
new file mode 100644
index 00000000..7547e7f2
--- /dev/null
+++ b/SDK/Libraries/CoreSystem/Sources/File.c
@@ -0,0 +1,58 @@
+/* -------------------------------------------
+
+ Copyright SoftwareLabs
+
+------------------------------------------- */
+
+#include <Headers/Defines.h>
+#include <Headers/File.h>
+
+enum FileOp
+{
+ kFlushFile,
+ kReadFork,
+ kWriteFork,
+ kOpenFork,
+ kCloseFork,
+};
+
+/// @brief Opens a new file.
+/// @param path where to find it.
+/// @param rest the restrict (rw, rwe, r+, w+, r, w)
+/// @return FSRef the file.
+CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path,
+ const CharacterTypeUTF8* rest)
+{
+ CS_MUST_PASS(kSharedApplication);
+ CS_MUST_PASS(path && CSIsValidPath(path) == Yes);
+ CS_MUST_PASS(rest);
+
+ return kSharedApplication->Invoke(kSharedApplication, kCallOpenFile, path,
+ rest);
+}
+
+/// @brief Closes the file and flushes it to the said file.
+/// @param refCS the filesystem reference.
+/// @return
+CS_EXTERN_C VoidType CSCloseFile(FSRef refCS)
+{
+ CS_MUST_PASS(kSharedApplication);
+
+ kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile);
+ kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS);
+}
+
+/// @brief Check if filesystem path is valid.
+/// @param path
+/// @return
+CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path)
+{
+ CS_MUST_PASS(kSharedApplication);
+ CS_MUST_PASS(path);
+
+ return kSharedApplication->Invoke(kSharedApplication, kCallFileExists, path) ||
+ kSharedApplication->Invoke(kSharedApplication, kCallDirectoryExists, path) ||
+ kSharedApplication->Invoke(kSharedApplication, kCallSymlinkExists, path) ||
+ kSharedApplication->Invoke(kSharedApplication, kCallDriveExists, path) ||
+ kSharedApplication->Invoke(kSharedApplication, kCallDeviceExists, path);
+} \ No newline at end of file