1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);
}
|