|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | FSStat |
| struct | FSSearchIter |
Typedefs | |
| typedef enum FSPathStatEnum | FSPathStat |
| typedef struct FSStat | FSStat |
| typedef struct FSSearch | FSSearch |
| typedef struct FSSearchIter | FSSearchIter |
Enumerations | |
| enum | FSPathStatEnum { FS_Nonexistent , FS_Directory , FS_File } |
Functions | |
| void | pathFromPlatform (string *out, strref platformpath) |
| void | pathToPlatform (string *out, strref path) |
| void | fsCurDir (string *out) |
| bool | fsSetCurDir (strref cur) |
| bool | pathMakeAbsolute (string *out, strref path) |
| void | fsExe (string *out) |
| void | fsExeDir (string *out) |
| FSPathStat | fsStat (strref path, FSStat *stat) |
| bool | fsExist (strref path) |
| bool | fsIsDir (strref path) |
| bool | fsIsFile (strref path) |
| bool | fsSetTimes (strref path, int64 modified, int64 accessed) |
| bool | fsCreateDir (strref path) |
| bool | fsCreateAll (strref path) |
| bool | fsRemoveDir (strref path) |
| bool | fsDelete (strref path) |
| bool | fsRename (strref from, strref to) |
| bool | fsSearchInit (FSSearchIter *iter, strref path, strref pattern, bool stat) |
| bool | fsSearchNext (FSSearchIter *iter) |
| void | fsSearchFinish (FSSearchIter *iter) |
| bool | fsSearchValid (FSSearchIter *iter) |
This module provides direct access to the operating system's filesystem using platform-native paths. For platform-independent path manipulation, see path.h. For a virtual filesystem abstraction, see vfs.h.
All paths are UTF-8 encoded.
| typedef enum FSPathStatEnum FSPathStat |
Path type enumeration
Returned by fsStat to indicate what kind of filesystem object exists at a given path (if any).
| typedef struct FSSearchIter FSSearchIter |
Directory search result
Contains information about one entry found during directory iteration. The 'name' string is valid only until the next call to fsSearchNext or fsSearchFinish.
Filesystem object metadata
Contains timestamps and size information for a file or directory. All timestamps are in CX time format (microseconds since epoch).
| enum FSPathStatEnum |
| bool fsCreateAll | ( | strref | path | ) |
Creates a directory and all necessary parent directories
Recursively creates all directories in the path that don't already exist. Similar to 'mkdir -p' on Unix. Safe to call on existing directories.
| path | Full path to create |
| bool fsCreateDir | ( | strref | path | ) |
Creates a single directory
Creates a new directory at the specified path. The parent directory must already exist. To create multiple levels of directories at once, use fsCreateAll() instead.
| path | Path where the new directory should be created |
| void fsCurDir | ( | string * | out | ) |
Gets the current working directory
Returns the OS's current working directory as a normalized CX path. This is a platform-specific concept and may vary per-thread on some systems.
| out | String to receive the current directory (prior contents destroyed) |
| bool fsDelete | ( | strref | path | ) |
Deletes a file
Removes a file from the filesystem. This cannot delete directories; use fsRemoveDir() for that.
| path | Path to the file to delete |
| void fsExe | ( | string * | out | ) |
Gets the full path to the currently running executable
Returns the absolute path to the executable file that is currently running. Useful for locating resources relative to the executable.
| out | String to receive the executable path (prior contents destroyed) |
| void fsExeDir | ( | string * | out | ) |
Gets the directory containing the currently running executable
Returns the parent directory of the current executable. Equivalent to calling pathParent on the result of fsExe().
| out | String to receive the executable directory (prior contents destroyed) |
|
inline |
Checks if a path exists in the filesystem
This is a convenience wrapper around fsStat that only checks existence without retrieving metadata or caring about the type.
| path | Path to check |
Definition at line 137 of file fs.h.
References FS_Nonexistent, and fsStat().
|
inline |
Checks if a path exists and is a directory
| path | Path to check |
Definition at line 146 of file fs.h.
References FS_Directory, and fsStat().
|
inline |
| bool fsRemoveDir | ( | strref | path | ) |
Removes an empty directory
Deletes a directory from the filesystem. The directory must be empty (contain no files or subdirectories). To delete files, use fsDelete().
| path | Path to the directory to remove |
| bool fsRename | ( | strref | from, |
| strref | to | ||
| ) |
Renames or moves a file or directory
Moves a file or directory from one path to another. Can be used to rename (if in the same directory) or move to a different directory. On most systems, this is atomic if both paths are on the same filesystem.
If 'to' already exists, behavior is platform-dependent:
| from | Current path of the file or directory |
| to | New path for the file or directory |
| void fsSearchFinish | ( | FSSearchIter * | iter | ) |
Completes directory iteration and releases resources
Must be called after fsSearchInit to clean up the iterator, even if iteration was terminated early. Safe to call multiple times or on an uninitialized iterator.
| iter | Search iterator to clean up |
| bool fsSearchInit | ( | FSSearchIter * | iter, |
| strref | path, | ||
| strref | pattern, | ||
| bool | stat | ||
| ) |
Begins iteration over directory contents
Initializes a directory search iterator. After this call, use fsSearchNext in a loop to retrieve entries. Always call fsSearchFinish when done, even if breaking out of the loop early.
| iter | Iterator structure to initialize (will be cleared first) |
| path | Directory path to search |
| pattern | Optional wildcard pattern to filter results (NULL for all entries). Patterns support * and ? wildcards (e.g., "*.txt") |
| stat | If true, populate the stat field for each entry (slower) |
Example:
| bool fsSearchNext | ( | FSSearchIter * | iter | ) |
Advances to the next directory entry
Call this in a loop after fsSearchInit to iterate through all matching entries. The iter->name field is updated with each entry.
| iter | Active search iterator (from fsSearchInit) |
|
inline |
Checks if a search iterator is valid and has a current entry. This can be used to make fsSearch loops more convenient.
| iter | Search iterator to check |
Example:
| bool fsSetCurDir | ( | strref | cur | ) |
Sets the current working directory
Changes the OS's current working directory. This affects relative path resolution for all filesystem operations in the process.
| cur | Path to set as current directory (can be relative or absolute) |
| bool fsSetTimes | ( | strref | path, |
| int64 | modified, | ||
| int64 | accessed | ||
| ) |
Sets the modification and access times for a filesystem object
Updates the timestamps on a file or directory. The creation time cannot be modified. Timestamps are in CX time format (microseconds since epoch).
| path | Path to the file or directory to modify |
| modified | New modification time |
| accessed | New access time |
| FSPathStat fsStat | ( | strref | path, |
| FSStat * | stat | ||
| ) |
Gets information about a filesystem object
Queries the filesystem for information about the object at the given path. This can determine if a path exists and what type of object it is, and optionally retrieve detailed metadata.
| path | Path to query (can be relative or absolute) |
| stat | Optional pointer to receive detailed metadata (can be NULL) |
Example:
Referenced by fsExist(), fsIsDir(), and fsIsFile().
| void pathFromPlatform | ( | string * | out, |
| strref | platformpath | ||
| ) |
Converts a platform-specific path into a normalized CX path
Platform-specific path formats:
C:\path\to\file or \\server\share\file/path/to/fileCX path format: namespace:/path/to/file
c:/path/to/file) UNC paths use unc namespace (unc:/server/share/file)/path/to/fileThe output path is normalized (forward slashes, redundant elements removed).
| out | String to receive the converted path (prior contents destroyed) |
| platformpath | Platform-specific path to convert |
| bool pathMakeAbsolute | ( | string * | out, |
| strref | path | ||
| ) |
Converts a relative path to an absolute path using the current directory
If the input path is already absolute, it is normalized and returned. If relative, it is resolved against the OS's current working directory.
| out | String to receive the absolute path (prior contents destroyed) |
| path | Relative or absolute path to convert |
| void pathToPlatform | ( | string * | out, |
| strref | path | ||
| ) |
Converts a normalized CX path into a platform-specific path
This is the inverse of pathFromPlatform. The output uses the native path format required by OS-level file operations.
| out | String to receive the platform path (prior contents destroyed) |
| path | CX normalized path to convert |