CBuild wiki
File system access abstraction layer.
License: GPL-3.0-or-later.
Dynamic array of paths
Get element from list of paths using its index.
const cbuild_pathlist_t*
list Path list object.size_t idx Element index.char** Pointer to an
element or NULL if index out of
bounds.
Free pathlist.
This function should really be used instead of simple free(list->data)
because pathlist allocated memory in two levels.
const cbuild_pathlist_t*
list Path list object.typedef enum {
CBUILD_FTYPE_MISSING = -1,
CBUILD_FTYPE_REGULAR = 0,
CBUILD_FTYPE_DIRECTORY = 1,
CBUILD_FTYPE_SYMLINK = 2,
CBUILD_FTYPE_OTHER = 3,
} cbuild_filetype_t;Type of file. Mostly cross-platform because no special Unix files are included.
Close file descriptor.
Open file for reading.
Open file for writing.
Create and open new pipe. File descriptors for both ends are provided.
POSIX read wrapper.
cbuild_fd_t fd File descriptor.void*
buf Buffer in which data will be
read.size_t nbytes Number of bytes to read.ssize_t Number of bytes
read or -1
on error.
POSIX read “wrapper”. This function
uses pathconst char*
only for error-reporting.
cbuild_fd_t fd File descriptor.void*
buf Buffer in which data will be
read.size_t nbytes Number of bytes to read.const char*
path File name used in error
reporting.ssize_t Number of bytes
read or -1
on error.
POSIX write wrapper.
cbuild_fd_t fd File descriptor.const void*
buf Buffer from which data will be
written.size_t nbytes Number of bytes to write.ssize_t Number of bytes
written or -1
on error.
CBUILDDEF ssize_t cbuild_fd_write_file(cbuild_fd_t fd, const void* buf,
size_t nbytes, const char* path);POSIX write “wrapper”. This
function uses pathconst char*
only for error-reporting.
cbuild_fd_t fd File descriptor.const void*
buf Buffer from which data will be
written.size_t nbytes Number of bytes to write.const char*
path File name used in error
reporting.ssize_t Number of bytes
written or -1
on error.
Get length of file in bytes.
ssize_t Length of file
in bytes or -1 on error.
Read file into string builder.
Overwrite file with string builder content.
Copy file.
This copies file by reading from srcconst char*
and writing to dstconst char*.
“Chunked” copy is used to limit memory usage.
Move file.
Uses optimal method for moving file, but in worst case falls back to
cbuild_file_copy(src, dst); cbuild_file_remove(src).
Rename file. Alias to cbuild_file_move.
Uses optimal method for moving file, but in worst case falls back to
cbuild_file_copy(src, dst); cbuild_file_remove(src).
const char*
srcconst char*
dstbool
Check if file exists.
Delete file.
Create symbolic link. Will overwrite dstconst char*
if it exists.
Recursively copy a directory.
Move a directory.
Uses optimal method for moving directory, but in worst case falls
back to cbuild_dir_copy(src, dst); cbuild_dir_remove(src).
Rename a directory. Alias to cbuild_dir_move.
Uses optimal method for moving directory, but in worst case falls
back to cbuild_dir_copy(src, dst); cbuild_dir_remove(src).
const char*
srcconst char*
dstbool
Delete directory.
Check if directory exists.
List all files in directory.
const char*
path Path to a directory.cbuild_pathlist_t*
elements List of elements in
directory.Get current working directory.
char* Current working
directory values. Allocated __CBUILD_MALLOC.
Set current working directory.
Create new directory.
enum cbuild_dir_walk_result_t {
CBUILD_DIR_WALK_CONTINUE = 0,
CBUILD_DIR_WALK_NO_ENTER,
CBUILD_DIR_WALK_STOP = -1,
};Result for cbuild_dir_walk_func_t.
typedef struct cbuild_dir_walk_func_args_t {
const char* path;
cbuild_filetype_t type;
size_t level;
enum cbuild_dir_walk_result_t* result;
void* context;
} cbuild_dir_walk_func_args_t;Arguments for cbuild_dir_walk_func_t.
This structure can be divided into multiple sections:
const char*
path Path to the file system object
object (relative and including directory passed to cbuild_dir_walk.cbuild_filetype_t type Type of current file-system
object.size_t level How deep iteration goes
(0 means base directory).void*
context Some arguments passed by
user.enum cbuild_dir_walk_result_t*
result Return value.Function used as callback by directory walker.
bool false
means error.
Arguments to a directory walker.
void*
context Some arguments that will be
passed to callback.bool visit_dir_last Inverts order. Now all
child files are visited first and parent directory is visited last.CBUILDDEF bool cbuild_dir_walk_opt(const char* path, cbuild_dir_walk_func_t func,
struct cbuild_dir_walk_opts_t opts);Walk over dir. Takes path, callback and some optional options. Semi-internal function.
Walk over dir.
const char*
path Path to a file.cbuild_dir_walk_func_t callback Function that will be called for
each file system object....cbuild_dir_walk_opts_t
… Fields of configuration structure in
initializer-list form.Open directory.
Get next element from directory.
cbuild_dir_t dir Directory handle.
const char**
element Return value for
filename.
0 No error and
directory iterator is still not empty.
1 No error but
directory iterator is empty. elementconst char**
is NULL.
-1 Error
happened.
Close directory.
Get type of file.
Optional arguments for cbuild_path_ext.
int dot Get extensions after n-th dot from the
end. 0 is default value (for now it is same as
1).Get extension of specific file. Semi-internal. File pointer by pathconst char*
is not checked in any way.
char* String allocated
via cbuild_temp_malloc.
Get extension of specific file. File pointer by pathconst char*
is not checked in any way.
const char*
path Path to a file....cbuild_path_ext_opts_t
… Fields of configuration structure in
initializer-list form.Get file name with extension (all after last /). For
directories special case exists that strips last / if it is
last character. File pointer by pathconst char*
is not checked in any way.
char* String allocated
via cbuild_temp_malloc.
Get base name (all before last /). For directories
special case exists that strips last / if it is last
character. File pointer by pathconst char*
is not checked in any way.
char* String allocated
via cbuild_temp_malloc.
Normalize path. All normalization is based on heuristics and does not
involve such steps as eg. symlink resolving. File pointer by pathconst char*
is not checked in any way.
char* String allocated
via cbuild_temp_malloc.