This section contains abstracted file system and I/O utilities. More...
Macros | |
#define | RU_WALK_FOLDER_FIRST 0x1 |
#define | RU_WALK_FOLDER_LAST 0x2 |
#define | RU_WALK_NO_RECURSE 0x4 |
#define | RU_WALK_NO_SELF 0x8 |
#define | RU_WALK_UNIX_SLASHES 0x10 |
Typedefs | |
typedef struct stat | ruStat_t |
typedef bool(* | entryFilter) (trans_chars folderPath, trans_chars fileName, bool isFolder, ptr ctx) |
A function that is called with each entry of a ruFolderWalk to decide whether that entry should be processed or not. More... | |
typedef int32_t(* | entryMgr) (trans_chars fullPath, bool isFolder, ptr ctx) |
A function that is called with each entry of a ruFolderWalk. More... | |
Functions | |
RUAPI bool | ruFileExists (trans_chars filename) |
RUAPI bool | ruIsFile (trans_chars filename) |
RUAPI bool | ruIsDir (trans_chars filename) |
RUAPI bool | ruIsExecutable (trans_chars filename) |
RUAPI bool | ruIsSymlink (trans_chars filename) |
RUAPI int32_t | ruDiskFree (trans_chars path, uint64_t *total, uint64_t *avail) |
RUAPI int32_t | ruStat (trans_chars filepath, ruStat_t *dest) |
RUAPI rusize | ruFileSize (trans_chars filePath, int32_t *code) |
Return the size of the given file if it exists. More... | |
RUAPI sec_t | ruFileUtcTime (trans_chars filePath, int32_t *code) |
Return the UTC modification date of the given file if it exists. More... | |
RUAPI int32_t | ruFileSetUtcTime (trans_chars filePath, sec_t date) |
Set UTC access and mod time of given filePath to given date. More... | |
RUAPI int | ruOpen (trans_chars filepath, int flags, int mode, int32_t *code) |
RUAPI FILE * | ruFOpen (trans_chars filepath, trans_chars mode, int32_t *code) |
RUAPI int | ruOpenTmp (char *pathTemplate, int flags, int mode, int32_t *code) |
RUAPI rusize_s | ruWrite (int oh, trans_ptr contents, rusize length) |
RUAPI int32_t | ruFileSetContents (trans_chars filename, trans_chars contents, rusize length) |
RUAPI int | ruFileGetContents (trans_chars filename, alloc_chars *contents, rusize *length) |
RUAPI int | ruFileCopy (trans_chars srcpath, trans_chars destpath) |
Copies srcpath to destpath. More... | |
RUAPI int | ruFileRename (trans_chars oldName, trans_chars newName) |
RUAPI int | ruFileTryRename (trans_chars oldName, trans_chars newName) |
Renames a given file like ruFileRename, but fails when newName already exists instead of overwriting it. More... | |
RUAPI int | ruFileRemove (trans_chars filename) |
RUAPI int32_t | ruFilteredFolderWalk (trans_chars folder, uint32_t flags, entryFilter filter, entryMgr actor, ptr ctx) |
Like ruFolderWalk with additional filtering capability. Folder entries . and .. are not passed to filter. More... | |
RUAPI int32_t | ruFolderWalk (trans_chars folder, uint32_t flags, entryMgr actor, ptr ctx) |
Decends into given folder depth first and calls actor on each entry. Folder entries . and .. are not passed to actor. More... | |
RUAPI ru_int | ruFolderEntries (trans_chars folder) |
Returns the number of folder entries including itself. More... | |
RUAPI int32_t | ruFolderRemove (trans_chars folder) |
Recursively delete given folder and all it's sub contents. If given path is a file or symlink, it will also be removed. More... | |
RUAPI int32_t | ruMkdir (trans_chars pathname, int mode, bool deep) |
RUAPI alloc_chars | ruDirName (trans_chars filePath) |
Returns the dirname part of a full path without the trailing slash. More... | |
RUAPI perm_chars | ruBaseName (perm_chars filePath) |
Returns the filename of a path with the preceding path removed. More... | |
RUAPI perm_chars | ruFileExtension (perm_chars filePath) |
Returns the extension part of the given file name if there is one. More... | |
RUAPI alloc_chars | ruFullPath (trans_chars filePath) |
Returns an absolute filepath leading to the given relative path. More... | |
RUAPI alloc_chars | ruPathJoinNative (trans_chars base, trans_chars file) |
Returns base and file joined with the filesystem slash in a new string. More... | |
RUAPI alloc_chars | ruPathJoin (trans_chars base, trans_chars file) |
Returns base and file joined with the a unix filesystem slash in a new string. More... | |
RUAPI alloc_chars | ruPathMultiJoin (int parts,...) |
Return a path by concatenating the given parts number of parameters using a unix style directory slash. More... | |
RUAPI alloc_chars | ruPathMultiJoinNative (int parts,...) |
Return a path by concatenating the given parts number of parameters using the platform native directory slash. More... | |
This section contains abstracted file system and I/O utilities.
#define RU_WALK_FOLDER_FIRST 0x1 |
Used by ruFolderWalk to specify that the folder be handled before its contents.
#define RU_WALK_FOLDER_LAST 0x2 |
Used by ruFolderWalk to specify that the folder be handled after its contents.
#define RU_WALK_NO_RECURSE 0x4 |
Used by ruFolderWalk to specify whether to not recurse into subfolders.
#define RU_WALK_NO_SELF 0x8 |
Used by ruFolderWalk to specify not to process the top level folder.
#define RU_WALK_UNIX_SLASHES 0x10 |
Used by ruFolderWalk to specify passing paths with unix style directory slashes to the callbacks. Ignored on Unix platforms.
typedef bool(* entryFilter) (trans_chars folderPath, trans_chars fileName, bool isFolder, ptr ctx) |
A function that is called with each entry of a ruFolderWalk to decide whether that entry should be processed or not.
folderPath | The full file path to the folder under which fileName resides. Must be copied to persist. Folder may or may not contain a trailing slash. |
fileName | The file base name of the current entry. Must be copied to persist. |
isFolder | whether this is a folder. |
ctx | a user definable context. |
typedef int32_t(* entryMgr) (trans_chars fullPath, bool isFolder, ptr ctx) |
A function that is called with each entry of a ruFolderWalk.
fullPath | The full file path to the entry in question. Must be copied to persist. Folder may or may not contain a trailing slash. |
isFolder | whether this is a folder. |
ctx | a user definable context. |
typedef struct stat ruStat_t |
An abstracted version of struct stat.
RUAPI perm_chars ruBaseName | ( | perm_chars | filePath | ) |
Returns the filename of a path with the preceding path removed.
filePath | File path to return the basename of. |
RUAPI alloc_chars ruDirName | ( | trans_chars | filePath | ) |
Returns the dirname part of a full path without the trailing slash.
filePath | File path to return the dirname of. |
RUAPI int32_t ruDiskFree | ( | trans_chars | path, |
uint64_t * | total, | ||
uint64_t * | avail | ||
) |
Returns the total and avail size of the partition where path resides on.
path | Path whose partition to examine. |
total | Optional, Where total partition size will be stored in bytes |
avail | Optional, Where left over user partition size will be stored in bytes. |
RUAPI int ruFileCopy | ( | trans_chars | srcpath, |
trans_chars | destpath | ||
) |
Copies srcpath to destpath.
srcpath | file to copy |
destpath | path to copy srcpath to |
RUAPI bool ruFileExists | ( | trans_chars | filename | ) |
Checks whether a file or folder exists.
filename | Name of file, folder or other filesystem entity. |
RUAPI perm_chars ruFileExtension | ( | perm_chars | filePath | ) |
Returns the extension part of the given file name if there is one.
filePath | File path to get extension from |
RUAPI int ruFileGetContents | ( | trans_chars | filename, |
alloc_chars * | contents, | ||
rusize * | length | ||
) |
Reads the contents out of the given filepath into the variable and sets the length.
filename | Path to the file to read. |
contents | Where to store the read content. Caller must use ruFree when done with it. |
length | Number of bytes in contents. |
RUAPI int ruFileRemove | ( | trans_chars | filename | ) |
Delete a given file or empty folder.
filename | File or folder to delete. |
RUAPI int ruFileRename | ( | trans_chars | oldName, |
trans_chars | newName | ||
) |
Renames a given file. This is equivalent to moving a file. Any previous file at the destination will be overwritten.
oldName | Old file path. |
newName | The new file path. |
RUAPI int32_t ruFileSetContents | ( | trans_chars | filename, |
trans_chars | contents, | ||
rusize | length | ||
) |
Write the string stored in contents into a new file at filename. Any old file at that location will be overwritten by the new file.
filename | Path to the file to create. |
contents | Contents to write into the file. This may be a NULL terminated encoding irrelevant string or binary data. If contents is NULL an empty file will be created. |
length | Length of the content. May be RU_SIZE_AUTO for a NULL terminated string. |
RUAPI int32_t ruFileSetUtcTime | ( | trans_chars | filePath, |
sec_t | date | ||
) |
Set UTC access and mod time of given filePath to given date.
filePath | file to set time on |
date | UTC time stamp to set file time to |
RUAPI rusize ruFileSize | ( | trans_chars | filePath, |
int32_t * | code | ||
) |
Return the size of the given file if it exists.
filePath | File path to get size of |
code | Where the status of the operation will be stored. RUE_OK on success else RUE_PARAMETER_NOT_SET if filename was NULL or RUE_FILE_NOT_FOUND if file didn't exists or RUE_CANT_OPEN_FILE if it was another error. Check errno for details. |
RUAPI int ruFileTryRename | ( | trans_chars | oldName, |
trans_chars | newName | ||
) |
Renames a given file like ruFileRename, but fails when newName already exists instead of overwriting it.
oldName | Old file path. |
newName | The new file path. |
RUAPI sec_t ruFileUtcTime | ( | trans_chars | filePath, |
int32_t * | code | ||
) |
Return the UTC modification date of the given file if it exists.
filePath | File path to get date of |
code | Where the status of the operation will be stored. RUE_OK on success else RUE_PARAMETER_NOT_SET if filename was NULL or RUE_FILE_NOT_FOUND if file didn't exists or RUE_CANT_OPEN_FILE if it was another error. Check errno for details. |
RUAPI int32_t ruFilteredFolderWalk | ( | trans_chars | folder, |
uint32_t | flags, | ||
entryFilter | filter, | ||
entryMgr | actor, | ||
ptr | ctx | ||
) |
Like ruFolderWalk with additional filtering capability. Folder entries . and .. are not passed to filter.
folder | Folder to start descending into. Does not accept / or \ |
flags | Flags of type RU_WALK_* to specify walking behavior. All flags may be specified. |
filter | Function to call with each entry to decide filtering |
actor | Function to call with each entry |
ctx | a user definable context to be passed to the entryFilter and entryMgr functions. |
RUAPI ru_int ruFolderEntries | ( | trans_chars | folder | ) |
Returns the number of folder entries including itself.
folder | Folder to count entries of |
RUAPI int32_t ruFolderRemove | ( | trans_chars | folder | ) |
Recursively delete given folder and all it's sub contents. If given path is a file or symlink, it will also be removed.
folder | Name of folder to delete. May not be "", "/" or "\\" |
RUAPI int32_t ruFolderWalk | ( | trans_chars | folder, |
uint32_t | flags, | ||
entryMgr | actor, | ||
ptr | ctx | ||
) |
Decends into given folder depth first and calls actor on each entry. Folder entries . and .. are not passed to actor.
folder | Folder to start descending into. Does not accept / or \ |
flags | Flags of type RU_WALK_* to specify walking behavior. All flags may be specified. |
actor | Function to call with each entry |
ctx | a user definable context to be passed to the entryMgr function. |
RUAPI FILE* ruFOpen | ( | trans_chars | filepath, |
trans_chars | mode, | ||
int32_t * | code | ||
) |
Abstracted version of the Posix fopen call.
filepath | Path to the file to open |
mode | File access mode such as r, r+, w, w+, a or a+. |
code | Parameter validation error or RUE_OK if parameters are good. |
RUAPI alloc_chars ruFullPath | ( | trans_chars | filePath | ) |
Returns an absolute filepath leading to the given relative path.
This function merely appends the given path to CWD if it's relative. It does not validate or process the given path in any other way.
filePath | File path to append the current working directory to if it is relative. |
RUAPI bool ruIsDir | ( | trans_chars | filename | ) |
Returns true if the given path exists and is a folder. On Unix if the underlying path is a symlink it is dereferenced and the status of the target is returned.
filename | File path to test |
RUAPI bool ruIsExecutable | ( | trans_chars | filename | ) |
Returns true if the given path exists and is executable. On Unix if the underlying path is a symlink it is dereferenced and the status of the target is returned. On Unix the file permissions are test for -x. On Windows the file extension is check for .com, .cmd, .bat, .exe and whatever extension is set in the PATHEXT environment variable.
filename | File path to test |
RUAPI bool ruIsFile | ( | trans_chars | filename | ) |
Returns true if the given path exists and is a regular file. On Unix if the underlying path is a symlink it is dereferenced and the status of the target is returned.
filename | File path to test |
RUAPI bool ruIsSymlink | ( | trans_chars | filename | ) |
Returns true if the given path exists and is a symbolic link (Unix only).
filename | File path to test |
RUAPI int32_t ruMkdir | ( | trans_chars | pathname, |
int | mode, | ||
bool | deep | ||
) |
Creates the requested folder with the requested permissions.
pathname | Folder to create |
mode | Permissions to set (Unix only). |
deep | Whether to create any upper level folders. |
RUAPI int ruOpen | ( | trans_chars | filepath, |
int | flags, | ||
int | mode, | ||
int32_t * | code | ||
) |
Abstracted version of the Posix open call.
filepath | Path to the file to open |
flags | File access flags such as O_RDONLY, O_WRONLY or O_RDWR. |
mode | Desired file permissions if this file is to be created. Ignored on Windows. |
code | Parameter validation error or RUE_OK if parameters are good. |
RUAPI int ruOpenTmp | ( | char * | pathTemplate, |
int | flags, | ||
int | mode, | ||
int32_t * | code | ||
) |
Creates and returns the file handle to a new temporary file.
pathTemplate | The filepath to where the file should be written. The folders where the file is to be created must already exist and be writable, and the pattern ^^^ will be replaced by random unique characters between a-z. The pathTemplate variable is actually modified and will point to the path corresponding to the returned file handle. |
flags | File access flags such as O_RDONLY, O_WRONLY or O_RDWR. |
mode | Desired file permissions if this file is to be created. Ignored on Windows. |
code | Parameter validation error or RUE_OK if parameters are good. |
RUAPI alloc_chars ruPathJoin | ( | trans_chars | base, |
trans_chars | file | ||
) |
Returns base and file joined with the a unix filesystem slash in a new string.
base | folder with or without trailing slash |
file | file anme to append |
RUAPI alloc_chars ruPathJoinNative | ( | trans_chars | base, |
trans_chars | file | ||
) |
Returns base and file joined with the filesystem slash in a new string.
base | folder with or without trailing slash |
file | file anme to append |
RUAPI alloc_chars ruPathMultiJoin | ( | int | parts, |
... | |||
) |
Return a path by concatenating the given parts number of parameters using a unix style directory slash.
The returned path will have the leading slash supplied with the first folder argument. There will be no trailing slash returned.
parts | Number of folder name that follow |
... | parts number of folder names to concatenate. Trailing slashes and leading slashes after the second folder are accounted for. |
RUAPI alloc_chars ruPathMultiJoinNative | ( | int | parts, |
... | |||
) |
Return a path by concatenating the given parts number of parameters using the platform native directory slash.
The returned path will have the leading slash supplied with the first folder argument. There will be no trailing slash returned.
parts | Number of folder name that follow |
... | parts number of folder names to concatenate. Trailing slashes and leading slashes after the second folder are accounted for. |
RUAPI int32_t ruStat | ( | trans_chars | filepath, |
ruStat_t * | dest | ||
) |
Populates the given ruStat_t with the data of the filepath if it exists.
filepath | File path to test |
dest | Pointer to ruStat_t to populate. |