Contains common file related functions. More...
Go to the source code of this file.
Macros | |
#define | QSC_FILEUTILS_CHUNK_SIZE 4096ULL |
[size_t] The default file chunk size. | |
#define | QSC_FILEUTILS_MAX_EXTENSION 16ULL |
[size_t] The maximum file extension size. | |
#define | QSC_FILEUTILS_MAX_FILENAME QSC_SYSTEM_MAX_PATH |
[size_t] The maximum file name size. | |
#define | QSC_FILEUTILS_MAX_PATH QSC_SYSTEM_MAX_PATH |
[size_t] The maximum file path size. | |
Enumerations | |
enum | qsc_fileutils_access_rights { qsc_fileutils_access_exists = 0x00U , qsc_fileutils_access_read = 0x04U , qsc_fileutils_access_write = 0x02U , qsc_fileutils_access_execute = 0x06U } |
Enumerates the file access rights. More... | |
enum | qsc_fileutils_mode { qsc_fileutils_mode_none = 0x00U , qsc_fileutils_mode_read = 0x01U , qsc_fileutils_mode_read_update = 0x02U , qsc_fileutils_mode_write = 0x03U , qsc_fileutils_mode_write_update = 0x04U , qsc_fileutils_mode_append = 0x05U , qsc_fileutils_mode_append_update = 0x06U } |
Enumerates the file open modes. More... | |
Functions | |
QSC_EXPORT_API bool | qsc_fileutils_append_to_file (const char *fpath, const char *stream, size_t length) |
Append an array of characters to a file. | |
QSC_EXPORT_API size_t | qsc_fileutils_copy_file_to_object (const char *fpath, void *obj, size_t length) |
Copy a file to an object. | |
QSC_EXPORT_API size_t | qsc_fileutils_copy_file_to_stream (const char *fpath, char *stream, size_t length) |
Copy elements from a file to a byte array. | |
QSC_EXPORT_API bool | qsc_fileutils_copy_object_to_file (const char *fpath, const void *obj, size_t length) |
Copy an object to a file. | |
QSC_EXPORT_API bool | qsc_fileutils_copy_stream_to_file (const char *fpath, const char *stream, size_t length) |
Copy the contents of a stream to a file. | |
QSC_EXPORT_API bool | qsc_fileutils_create (const char *fpath) |
Create a new file. | |
QSC_EXPORT_API bool | qsc_fileutils_delete (const char *fpath) |
Delete a file. | |
QSC_EXPORT_API bool | qsc_fileutils_erase (const char *fpath) |
Erase a file's contents. | |
QSC_EXPORT_API bool | qsc_fileutils_file_copy (const char *inpath, const char *outpath) |
Copy a file to a new location. | |
QSC_EXPORT_API bool | qsc_fileutils_get_access (const char *fpath, qsc_fileutils_access_rights level) |
Test a user's access right to a file. | |
QSC_EXPORT_API size_t | qsc_fileutils_get_directory (char *directory, size_t dirlen, const char *fpath) |
Get the file directory. | |
QSC_EXPORT_API size_t | qsc_fileutils_get_extension (char *extension, size_t extlen, const char *fpath) |
Get the file extension. | |
QSC_EXPORT_API size_t | qsc_fileutils_get_name (char *name, size_t namelen, const char *fpath) |
Get the file name. | |
QSC_EXPORT_API int64_t | qsc_fileutils_get_line (char **line, size_t *length, FILE *fp) |
Reads a line of text from a formatted file. | |
QSC_EXPORT_API size_t | qsc_fileutils_get_size (const char *fpath) |
Get the file size in bytes. | |
QSC_EXPORT_API bool | qsc_fileutils_get_working_directory (char *fpath) |
Get the working directory fpath. | |
QSC_EXPORT_API size_t | qsc_fileutils_list_files (char *result, size_t reslen, const char *directory) |
Get the filenames in a directory delineated with a newline. | |
QSC_EXPORT_API void | qsc_fileutils_close (FILE *fp) |
Close a file. | |
QSC_EXPORT_API bool | qsc_fileutils_exists (const char *fpath) |
Test to see if a file exists. | |
QSC_EXPORT_API FILE * | qsc_fileutils_open (const char *fpath, qsc_fileutils_mode mode, bool binary) |
Open a file and return the handle. | |
QSC_EXPORT_API size_t | qsc_fileutils_read (char *output, size_t otplen, size_t position, FILE *fp) |
Read data from a file into an output stream. | |
QSC_EXPORT_API size_t | qsc_fileutils_safe_read (const char *fpath, size_t position, char *output, size_t length) |
Read data from a binary file. | |
QSC_EXPORT_API size_t | qsc_fileutils_safe_write (const char *fpath, size_t position, const char *input, size_t length) |
Write data to a binary file. | |
QSC_EXPORT_API bool | qsc_fileutils_seekto (FILE *fp, size_t position) |
Set the file pointer position. | |
QSC_EXPORT_API int64_t | qsc_fileutils_read_line (const char *fpath, char *buffer, size_t buflen, size_t linenum) |
Read a line of text from a file. | |
QSC_EXPORT_API bool | qsc_fileutils_truncate_file (FILE *fp, size_t length) |
Truncate a file to a specified byte size. | |
QSC_EXPORT_API bool | qsc_fileutils_valid_path (const char *fpath) |
Checks if the fpath is valid. | |
QSC_EXPORT_API size_t | qsc_fileutils_write (const char *input, size_t inplen, size_t position, FILE *fp) |
Write data to a file. | |
QSC_EXPORT_API bool | qsc_fileutils_write_line (const char *fpath, const char *input, size_t inplen) |
Append a line of text to the end of a file. | |
QSC_EXPORT_API void | qsc_fileutils_zeroise (const char *fpath) |
Truncate a file to zero bytes. | |
Contains common file related functions.
Provides a suite of file utility functions for reading, writing, copying, and managing files and directories. This includes operations such as appending to files, copying files to objects or streams, checking file existence and access rights, retrieving file size, and listing files in a directory.
enum qsc_fileutils_mode |
Enumerates the file open modes.
QSC_EXPORT_API bool qsc_fileutils_append_to_file | ( | const char * | fpath, |
const char * | stream, | ||
size_t | length ) |
Append an array of characters to a file.
Writes new data to the end of a binary file.
fpath | [const char*] The full fpath to the file. |
stream | [const char*] The array to write to the file. |
length | [size_t] The stream size. |
QSC_EXPORT_API void qsc_fileutils_close | ( | FILE * | fp | ) |
Close a file.
fp | [FILE*] The file pointer. |
QSC_EXPORT_API size_t qsc_fileutils_copy_file_to_object | ( | const char * | fpath, |
void * | obj, | ||
size_t | length ) |
Copy a file to an object.
fpath | [const char*] The full fpath to the file. |
obj | [void*] The object to write to. |
length | [size_t] The size of the object. |
QSC_EXPORT_API size_t qsc_fileutils_copy_file_to_stream | ( | const char * | fpath, |
char * | stream, | ||
size_t | length ) |
Copy elements from a file to a byte array.
fpath | [const char*] The full fpath to the stream. |
stream | [char*] The stream receiving the file. |
length | [size_t] The number of bytes to write to the stream. |
QSC_EXPORT_API bool qsc_fileutils_copy_object_to_file | ( | const char * | fpath, |
const void * | obj, | ||
size_t | length ) |
Copy an object to a file.
fpath | [const char*] The full fpath to the file. |
obj | [const void*] The object to write to the file. |
length | [size_t] The size of the object. |
QSC_EXPORT_API bool qsc_fileutils_copy_stream_to_file | ( | const char * | fpath, |
const char * | stream, | ||
size_t | length ) |
Copy the contents of a stream to a file.
fpath | [const char*] The full fpath to the file. |
stream | [const char*] The array to write to the file. |
length | [size_t] The length of the array. |
QSC_EXPORT_API bool qsc_fileutils_create | ( | const char * | fpath | ) |
Create a new file.
fpath | [const char*] The full fpath to the file to be created. |
QSC_EXPORT_API bool qsc_fileutils_delete | ( | const char * | fpath | ) |
Delete a file.
fpath | [const char*] The full fpath to the file to be deleted. |
QSC_EXPORT_API bool qsc_fileutils_erase | ( | const char * | fpath | ) |
Erase a file's contents.
fpath | [const char*] The full fpath to the file. |
QSC_EXPORT_API bool qsc_fileutils_exists | ( | const char * | fpath | ) |
Test to see if a file exists.
fpath | [const char*] The fully qualified fpath to the file. |
QSC_EXPORT_API bool qsc_fileutils_file_copy | ( | const char * | inpath, |
const char * | outpath ) |
Copy a file to a new location.
inpath | [const char*] The full fpath to the input file. |
outpath | [const char*] The full fpath to the output file. |
QSC_EXPORT_API bool qsc_fileutils_get_access | ( | const char * | fpath, |
qsc_fileutils_access_rights | level ) |
Test a user's access right to a file.
fpath | [const char*] The fully qualified fpath to the file. |
level | [qsc_fileutils_access_rights] The access level to check. |
QSC_EXPORT_API size_t qsc_fileutils_get_directory | ( | char * | directory, |
size_t | dirlen, | ||
const char * | fpath ) |
Get the file directory.
directory | [char*] The output directory buffer. |
dirlen | [size_t] The length of the directory buffer. |
fpath | [const char*] The full fpath to the file. |
QSC_EXPORT_API size_t qsc_fileutils_get_extension | ( | char * | extension, |
size_t | extlen, | ||
const char * | fpath ) |
Get the file extension.
extension | [char*] The output extension buffer. |
extlen | [size_t] The length of the extension buffer. |
fpath | [const char*] The full fpath to the file. |
QSC_EXPORT_API int64_t qsc_fileutils_get_line | ( | char ** | line, |
size_t * | length, | ||
FILE * | fp ) |
Reads a line of text from a formatted file.
line | [char**] Pointer to the line buffer (dynamically allocated). |
length | [size_t*] Pointer to the buffer size. |
fp | [FILE*] The file stream handle. |
QSC_EXPORT_API size_t qsc_fileutils_get_name | ( | char * | name, |
size_t | namelen, | ||
const char * | fpath ) |
Get the file name.
name | [char*] The output file name buffer. |
namelen | [size_t] The length of the name buffer. |
fpath | [const char*] The full fpath to the file. |
QSC_EXPORT_API size_t qsc_fileutils_get_size | ( | const char * | fpath | ) |
Get the file size in bytes.
fpath | [const char*] The full fpath to the file. |
QSC_EXPORT_API bool qsc_fileutils_get_working_directory | ( | char * | fpath | ) |
Get the working directory fpath.
fpath | [char*] The output buffer for the current working directory. |
QSC_EXPORT_API size_t qsc_fileutils_list_files | ( | char * | result, |
size_t | reslen, | ||
const char * | directory ) |
Get the filenames in a directory delineated with a newline.
result | [char*] The output result string. |
reslen | [size_t] The length of the output string. |
directory | [const char*] The starting directory. |
QSC_EXPORT_API FILE * qsc_fileutils_open | ( | const char * | fpath, |
qsc_fileutils_mode | mode, | ||
bool | binary ) |
Open a file and return the handle.
fpath | [const char*] The fully qualified file fpath. |
mode | [qsc_fileutils_mode] The file access mode. |
binary | [bool] Open the file in binary mode (true) or ANSI mode (false). |
QSC_EXPORT_API size_t qsc_fileutils_read | ( | char * | output, |
size_t | otplen, | ||
size_t | position, | ||
FILE * | fp ) |
Read data from a file into an output stream.
output | [char*] The output buffer. |
otplen | [size_t] The size of the output buffer. |
position | [size_t] The starting position within the file. |
fp | [FILE*] The file pointer. |
QSC_EXPORT_API int64_t qsc_fileutils_read_line | ( | const char * | fpath, |
char * | buffer, | ||
size_t | buflen, | ||
size_t | linenum ) |
Read a line of text from a file.
fpath | [const char*] The full fpath to the file. |
buffer | [char*] The string buffer. |
buflen | [size_t] The size of the string buffer. |
linenum | [size_t] The line number to read. |
QSC_EXPORT_API size_t qsc_fileutils_safe_read | ( | const char * | fpath, |
size_t | position, | ||
char * | output, | ||
size_t | length ) |
Read data from a binary file.
fpath | [const char*] The file fpath. |
position | [size_t] The position to start reading from. |
output | [char*] The output character stream. |
length | [size_t] The number of bytes to read. |
QSC_EXPORT_API size_t qsc_fileutils_safe_write | ( | const char * | fpath, |
size_t | position, | ||
const char * | input, | ||
size_t | length ) |
Write data to a binary file.
fpath | [const char*] The file fpath. |
position | [size_t] The position to start writing to. |
input | [const char*] The input character string. |
length | [size_t] The number of bytes to write. |
QSC_EXPORT_API bool qsc_fileutils_seekto | ( | FILE * | fp, |
size_t | position ) |
Set the file pointer position.
fp | [FILE*] The file pointer. |
position | [size_t] The position within the file. |
QSC_EXPORT_API bool qsc_fileutils_truncate_file | ( | FILE * | fp, |
size_t | length ) |
Truncate a file to a specified byte size.
fp | [FILE*] The file pointer. |
length | [size_t] The new file size. |
QSC_EXPORT_API bool qsc_fileutils_valid_path | ( | const char * | fpath | ) |
Checks if the fpath is valid.
fpath | [const char*] The full fpath to the file. |
QSC_EXPORT_API size_t qsc_fileutils_write | ( | const char * | input, |
size_t | inplen, | ||
size_t | position, | ||
FILE * | fp ) |
Write data to a file.
input | [const char*] The input buffer. |
inplen | [size_t] The size of the input buffer. |
position | [size_t] The starting position within the file. |
fp | [FILE*] The file pointer. |
QSC_EXPORT_API bool qsc_fileutils_write_line | ( | const char * | fpath, |
const char * | input, | ||
size_t | inplen ) |
Append a line of text to the end of a file.
fpath | [const char*] The file fpath. |
input | [const char*] The input buffer. |
inplen | [size_t] The size of the input buffer. |
QSC_EXPORT_API void qsc_fileutils_zeroise | ( | const char * | fpath | ) |
Truncate a file to zero bytes.
fpath | [const char*] The file fpath. |