CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
fs.h
Go to the documentation of this file.
1
3
13
14#pragma once
15
16#include <cx/cx.h>
17
18CX_C_BEGIN
19
35void pathFromPlatform(_Inout_ string* out, _In_opt_ strref platformpath);
36
44void pathToPlatform(_Inout_ string* out, _In_opt_ strref path);
45
52void fsCurDir(_Inout_ string* out);
53
61bool fsSetCurDir(_In_opt_ strref cur);
62
71bool pathMakeAbsolute(_Inout_ string* out, _In_opt_ strref path);
72
79void fsExe(_Inout_ string* out);
80
87void fsExeDir(_Inout_ string* out);
88
98
103typedef struct FSStat {
104 uint64 size;
105 int64 created;
106 int64 modified;
107 int64 accessed;
109
128_Success_(return != FS_Nonexistent) FSPathStat fsStat(_In_opt_ strref path, _Out_opt_ FSStat* stat);
129
137_meta_inline bool fsExist(_In_opt_ strref path)
138{
139 return fsStat(path, NULL) != FS_Nonexistent;
140}
141
146_meta_inline bool fsIsDir(_In_opt_ strref path)
147{
148 return fsStat(path, NULL) == FS_Directory;
149}
150
155_meta_inline bool fsIsFile(_In_opt_ strref path)
156{
157 return fsStat(path, NULL) == FS_File;
158}
159
169bool fsSetTimes(_In_opt_ strref path, int64 modified, int64 accessed);
170
180bool fsCreateDir(_In_opt_ strref path);
181
190bool fsCreateAll(_In_opt_ strref path);
191
199bool fsRemoveDir(_In_opt_ strref path);
200
208bool fsDelete(_In_opt_ strref path);
209
223bool fsRename(_In_opt_ strref from, _In_opt_ strref to);
224
229typedef struct FSSearch FSSearch;
230
236typedef struct FSSearchIter {
237 string name;
238 int type;
240 // private
241 void* _search;
243
268bool fsSearchInit(_Out_ FSSearchIter* iter, _In_opt_ strref path, _In_opt_ strref pattern,
269 bool stat);
270
279bool fsSearchNext(_Inout_ FSSearchIter* iter);
280
288void fsSearchFinish(_Inout_ FSSearchIter* iter);
289
306_meta_inline bool fsSearchValid(_In_ FSSearchIter* iter)
307{
308 return iter->name;
309}
310
312
313CX_C_END
void fsSearchFinish(FSSearchIter *iter)
bool fsRename(strref from, strref to)
bool fsIsDir(strref path)
Definition fs.h:146
bool fsSearchValid(FSSearchIter *iter)
Definition fs.h:306
void fsExe(string *out)
void pathToPlatform(string *out, strref path)
bool fsSearchNext(FSSearchIter *iter)
void fsExeDir(string *out)
bool fsSetCurDir(strref cur)
bool fsIsFile(strref path)
Definition fs.h:155
void pathFromPlatform(string *out, strref platformpath)
bool fsRemoveDir(strref path)
FSPathStat fsStat(strref path, FSStat *stat)
void fsCurDir(string *out)
bool fsDelete(strref path)
bool fsSearchInit(FSSearchIter *iter, strref path, strref pattern, bool stat)
bool fsCreateDir(strref path)
enum FSPathStatEnum FSPathStat
bool fsExist(strref path)
Definition fs.h:137
bool fsSetTimes(strref path, int64 modified, int64 accessed)
struct FSSearch FSSearch
Definition fs.h:229
FSPathStatEnum
Definition fs.h:93
bool fsCreateAll(strref path)
bool pathMakeAbsolute(string *out, strref path)
@ FS_Directory
Path is a directory.
Definition fs.h:95
@ FS_File
Path is a regular file.
Definition fs.h:96
@ FS_Nonexistent
Path does not exist.
Definition fs.h:94
int type
FSPathStat type (FS_File or FS_Directory)
Definition fs.h:238
void * _search
Internal search state - do not access.
Definition fs.h:241
FSStat stat
File metadata (only valid if stat=true in fsSearchInit)
Definition fs.h:239
string name
Filename (not full path, valid until next search operation)
Definition fs.h:237
Definition fs.h:103
int64 accessed
Last access time.
Definition fs.h:107
int64 modified
Last modification time.
Definition fs.h:106
uint64 size
Size in bytes (0 for directories)
Definition fs.h:104
int64 created
Creation time (birth time)
Definition fs.h:105