summaryrefslogtreecommitdiffhomepage
path: root/Usr/Sys/CoreSystem/Sources/File.c
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-06-13 06:32:06 +0000
committerAmlal <amlalelmahrouss@icloud.com>2024-06-13 06:32:06 +0000
commit36ff25861676cd1f5fb94b901fa59b015c614bc5 (patch)
tree92d68c0e4ba1eeb0d608a917bfdc587909260e13 /Usr/Sys/CoreSystem/Sources/File.c
parent4e75e05a20ddd0dbca982e8f3bc2ea8043ed3a3f (diff)
parenta0b3442fe9978093326dc29d0938f1116eadd147 (diff)
Merged in MHR-23 (pull request #15)
MHR-23
Diffstat (limited to 'Usr/Sys/CoreSystem/Sources/File.c')
-rw-r--r--Usr/Sys/CoreSystem/Sources/File.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/Usr/Sys/CoreSystem/Sources/File.c b/Usr/Sys/CoreSystem/Sources/File.c
new file mode 100644
index 00000000..9f6b3b35
--- /dev/null
+++ b/Usr/Sys/CoreSystem/Sources/File.c
@@ -0,0 +1,69 @@
+/* -------------------------------------------
+
+ Copyright Zeta Electronics Corporation
+
+------------------------------------------- */
+
+#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);
+
+ CSFlushFile(refCS);
+
+ kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS);
+}
+
+/// @brief Flush file
+/// @param refCS the file reference.
+/// @return
+CS_EXTERN_C VoidType CSFlushFile(FSRef refCS)
+{
+ CS_MUST_PASS(kSharedApplication);
+
+ kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile);
+}
+
+/// @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