This documentation is under development!

fileutils

fileutils#

Cross-platform file utility functions.

Defines

FU_PATHS_CHUNKSIZE#

Chunk size for path allocation

__attribute__(x)

Typedefs

typedef enum _FUPlatform FUPlatform#

Platform

typedef DIR FUDir#

Directory state.

typedef struct _FUPaths FUPaths#

List of directory search pathes

typedef struct _FUIter FUIter#

File matching iterator.

Enums

enum [anonymous]#

Error codes

Values:

enumerator fu_PathError#
enumerator fu_OpenDirectoryError#
enum _FUPlatform#

Platform

Values:

enumerator fuUnknownPlatform#

Unknown platform

enumerator fuNative#

Platform we are compiling on

enumerator fuUnix#

Unix-like platforms; POSIX complient

enumerator fuWindows#

Windows

enumerator fuApple#

Apple - not yet supported…

enumerator fuLastPlatform#

Must always be the last

Functions

FUPlatform fu_native_platform(void)#

Returns native platform.

int fu_supported_platform(FUPlatform platform)#

Returns non-zero if platform is supported.

const char *fu_platform_name(FUPlatform platform)#

Returns a constant pointer to the name of platform.

FUPlatform fu_platform(const char *name)#

Returns the platform number corresponding to name or -1 on error.

const char *fu_dirsep(FUPlatform platform)#

Returns a pointer to directory separator for platform or NULL on error.

const char *fu_pathsep(FUPlatform platform)#

Returns a pointer to path separator for platform or NULL on error.

const char *fu_linesep(FUPlatform platform)#

Returns a pointer to line separator for platform or NULL on error.

int fu_isabs(const char *path)#

Returns non-zero if path is an absolute path.

int fu_iswinpath(const char *path, int len)#

Returns non-zero if path, of length len, is a Windows path.

A Windows path must start with a drive letter and colon (ex “C:”), but not followed by two forward slashes (ex “c://”, which is interpreted as an URL).

Alternatively a Windows path can start with two backward slashes indicating a network (UNC) path.

char *fu_join(const char *a, ...)#

Joins a set of pathname components, inserting ‘/’ as needed. The first path component is a. The last argument must be NULL.

If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.

Returns a pointer to a malloc’ed string or NULL on error.

char *fu_join_sep(int sep, const char *a, ...)#

Like fu_join(), but takes path separator as first argument.

char *fu_vjoin_sep(int sep, const char *a, va_list ap)#

Like fu_join_sep(), but takes a va_list instead of a variable number of arguments.

char *fu_lastsep(const char *path)#

Returns a pointer to the last directory separator in path.

char *fu_dirname(const char *path)#

Returns the directory component of path as a newly allocated string.

char *fu_basename(const char *path)#

Returns the final component of path as a newly allocated string.

const char *fu_fileext(const char *path)#

Returns a pointer to file extension of path (what follows after the last “.”).

char *fu_friendly_dirsep(char *path)#

Updates path to use more “user-friendly” directory separators.

On Unix-like systems this function does nothing.

On Windows, the following logic is applied:

  • path starts with “//” or “\”: ‘/’ -> ‘’

  • path starts with “C:” (where C is any character): ‘’ -> ‘/’

  • otherwise ‘’ -> ‘/’

Returns a pointer to path.

struct _FUPaths#
#include <fileutils.h>

List of directory search pathes

Public Members

size_t n#

Number of paths

size_t size#

Allocated number of paths

const char **paths#

NULL-terminated array of pointers to paths

FUPlatform platform#

Platform that returned paths should confirm to, defaults to native

const char *pathsep#

Path separator