DDraceNetwork Docs
Filesystem

Functions

void fs_listdir (const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user)
 
void fs_listdir_fileinfo (const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user)
 
int fs_makedir (const char *path)
 
int fs_removedir (const char *path)
 
int fs_makedir_rec_for (const char *path)
 
int fs_storage_path (const char *appname, char *path, int max)
 
int fs_is_file (const char *path)
 
int fs_is_dir (const char *path)
 
int fs_is_relative_path (const char *path)
 
int fs_chdir (const char *path)
 
char * fs_getcwd (char *buffer, int buffer_size)
 
const char * fs_filename (const char *path)
 
void fs_split_file_extension (const char *filename, char *name, size_t name_size, char *extension=nullptr, size_t extension_size=0)
 
int fs_parent_dir (char *path)
 
int fs_remove (const char *filename)
 
int fs_rename (const char *oldname, const char *newname)
 
int fs_file_time (const char *name, time_t *created, time_t *modified)
 

Detailed Description

Utilities for accessing the file system.

Function Documentation

◆ fs_chdir()

int fs_chdir ( const char *  path)

Changes the current working directory.

Parameters
pathNew working directory path.
Returns
0 on success, 1 on failure.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_file_time()

int fs_file_time ( const char *  name,
time_t *  created,
time_t *  modified 
)

Gets the creation and the last modification date of a file or directory.

Parameters
namePath of a file or directory.
createdPointer where the creation time will be stored.
modifiedPointer where the modification time will be stored.
Returns
0 on success, non-zero on failure.
Remarks
The strings are treated as zero-terminated strings.
Returned time is in seconds since UNIX Epoch.

◆ fs_filename()

const char * fs_filename ( const char *  path)

Gets the name of a file or folder specified by a path, i.e. the last segment of the path.

Parameters
pathPath from which to retrieve the filename.
Returns
Filename of the path.
Remarks
Supports forward and backward slashes as path segment separator.
No distinction between files and folders is being made.
The strings are treated as zero-terminated strings.

◆ fs_getcwd()

char * fs_getcwd ( char *  buffer,
int  buffer_size 
)

Gets the current working directory.

Parameters
bufferBuffer that will receive the current working directory.
buffer_sizeSize of the buffer.
Returns
Pointer to the buffer on success, nullptr on failure.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_is_dir()

int fs_is_dir ( const char *  path)

Checks if a folder exists.

Parameters
paththe path to check.
Returns
1 if a folder with the given path exists, 0 on failure or if the folder does not exist.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_is_file()

int fs_is_file ( const char *  path)

Checks if a file exists.

Parameters
paththe path to check.
Returns
1 if a file with the given path exists, 0 on failure or if the file does not exist.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_is_relative_path()

int fs_is_relative_path ( const char *  path)

Checks whether a given path is relative or absolute.

Parameters
pathPath to check.
Returns
1 if relative, 0 if absolute.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_listdir()

void fs_listdir ( const char *  dir,
FS_LISTDIR_CALLBACK  cb,
int  type,
void *  user 
)

Lists the files and folders in a directory.

Parameters
dirDirectory to list.
cbCallback function to call for each entry.
typeType of the directory.
userPointer to give to the callback.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_listdir_fileinfo()

void fs_listdir_fileinfo ( const char *  dir,
FS_LISTDIR_CALLBACK_FILEINFO  cb,
int  type,
void *  user 
)

Lists the files and folders in a directory and gets additional file information.

Parameters
dirDirectory to list.
cbCallback function to call for each entry.
typeType of the directory.
userPointer to give to the callback.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_makedir()

int fs_makedir ( const char *  path)

Creates a directory.

Parameters
pathDirectory to create.
Returns
0 on success. Negative value on failure.
Remarks
Does not create several directories if needed. "a/b/c" will result in a failure if b or a does not exist.
The strings are treated as zero-terminated strings.

◆ fs_makedir_rec_for()

int fs_makedir_rec_for ( const char *  path)

Recursively creates parent directories for a file or directory.

Parameters
pathFile or directory for which to create parent directories.
Returns
0 on success. Negative value on failure.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_parent_dir()

int fs_parent_dir ( char *  path)

Get the parent directory of a directory.

Parameters
pathPath of the directory. The parent will be store in this buffer as well.
Returns
0 on success, 1 on failure.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_remove()

int fs_remove ( const char *  filename)

Deletes a file.

Parameters
filenamePath of the file to delete.
Returns
0 on success, 1 on failure.
Remarks
The strings are treated as zero-terminated strings.
Returns an error if the path specifies a directory name.

◆ fs_removedir()

int fs_removedir ( const char *  path)

Removes a directory.

Parameters
pathDirectory to remove.
Returns
0 on success. Negative value on failure.
Remarks
Cannot remove a non-empty directory.
The strings are treated as zero-terminated strings.

◆ fs_rename()

int fs_rename ( const char *  oldname,
const char *  newname 
)

Renames the file or directory. If the paths differ the file will be moved.

Parameters
oldnameThe current path of a file or directory.
newnameThe new path for the file or directory.
Returns
0 on success, 1 on failure.
Remarks
The strings are treated as zero-terminated strings.

◆ fs_split_file_extension()

void fs_split_file_extension ( const char *  filename,
char *  name,
size_t  name_size,
char *  extension = nullptr,
size_t  extension_size = 0 
)

Splits a filename into name (without extension) and file extension.

Parameters
filenameThe filename to split.
nameBuffer that will receive the name without extension, may be nullptr.
name_sizeSize of the name buffer (ignored if name is nullptr).
extensionBuffer that will receive the extension, may be nullptr.
extension_sizeSize of the extension buffer (ignored if extension is nullptr).
Remarks
Does NOT handle forward and backward slashes.
No distinction between files and folders is being made.
The strings are treated as zero-terminated strings.

◆ fs_storage_path()

int fs_storage_path ( const char *  appname,
char *  path,
int  max 
)

Fetches per user configuration directory.

Parameters
appnameName of the application.
pathBuffer that will receive the storage path.
maxSize of the buffer.
Returns
0 on success. Negative value on failure.
Remarks
Returns ~/.appname on UNIX based systems.
Returns ~/Library/Applications Support/appname on macOS.
Returns APPDATA%/Appname on Windows based systems.
The strings are treated as zero-terminated strings.