src/basedir.c File Reference
Implementation of the XDG Base Directory specification.
More...
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <errno.h>
#include <basedir.h>
#include <basedir_fs.h>
|
Classes |
struct | _xdgCachedData |
Defines |
#define | FALSE 0 |
#define | TRUE 1 |
#define | xdgZeroMemory(p, n) memset(p, 0, n) |
#define | DIR_SEPARATOR_CHAR '/' |
#define | DIR_SEPARATOR_STR "/" |
#define | PATH_SEPARATOR_CHAR ':' |
#define | PATH_SEPARATOR_STR ":" |
#define | NO_ESCAPES_IN_PATHS |
#define | MAX(a, b) ((b) > (a) ? (b) : (a)) |
Typedefs |
typedef struct _xdgCachedData | xdgCachedData |
Functions |
xdgHandle * | xdgInitHandle (xdgHandle *handle) |
void | xdgWipeHandle (xdgHandle *handle) |
int | xdgUpdateData (xdgHandle *handle) |
int | xdgMakePath (const char *path, mode_t mode) |
const char * | xdgDataHome (xdgHandle *handle) |
const char * | xdgConfigHome (xdgHandle *handle) |
const char *const * | xdgDataDirectories (xdgHandle *handle) |
const char *const * | xdgSearchableDataDirectories (xdgHandle *handle) |
const char *const * | xdgConfigDirectories (xdgHandle *handle) |
const char *const * | xdgSearchableConfigDirectories (xdgHandle *handle) |
const char * | xdgCacheHome (xdgHandle *handle) |
char * | xdgDataFind (const char *relativePath, xdgHandle *handle) |
char * | xdgConfigFind (const char *relativePath, xdgHandle *handle) |
FILE * | xdgDataOpen (const char *relativePath, const char *mode, xdgHandle *handle) |
FILE * | xdgConfigOpen (const char *relativePath, const char *mode, xdgHandle *handle) |
Detailed Description
Implementation of the XDG Base Directory specification.
Function Documentation
const char* xdgCacheHome |
( |
xdgHandle * |
handle |
) |
|
Base directory for user specific non-essential data files.
- Parameters:
-
- Returns:
- a path as described by the standards.
const char* const* xdgConfigDirectories |
( |
xdgHandle * |
handle |
) |
|
Preference-ordered set of base directories to search for configuration files in addition to the $XDG_CONFIG_HOME base directory.
- Parameters:
-
- Returns:
- A null-terminated list of directory strings.
char* xdgConfigFind |
( |
const char * |
relativePath, |
|
|
xdgHandle * |
handle | |
|
) |
| | |
Find all existing config files corresponding to relativePath. Consider as performing
on every possible
filename
and returning the successful
filename
s.
- Parameters:
-
| relativePath | Path to scan for. |
| handle | Handle to data cache, initialized with xdgInitHandle(). |
- Returns:
- A sequence of null-terminated strings terminated by a double-null (empty string) and allocated using malloc(), e.g.:
"/etc/xdg\0/home/jdoe/.config\0"
const char* xdgConfigHome |
( |
xdgHandle * |
handle |
) |
|
Base directory for user specific configuration files.
- Parameters:
-
- Returns:
- a path as described by the standards.
FILE* xdgConfigOpen |
( |
const char * |
relativePath, |
|
|
const char * |
mode, |
|
|
xdgHandle * |
handle | |
|
) |
| | |
Open first possible config file corresponding to relativePath. Consider as performing
on every possible
filename
and returning the first successful
filename
or
NULL
.
- Parameters:
-
| relativePath | Path to scan for. |
| mode | Mode with which to attempt to open files (see fopen modes). |
| handle | Handle to data cache, initialized with xdgInitHandle(). |
- Returns:
- File pointer if successful else
NULL
. Client must use fclose
to close file.
const char* const* xdgDataDirectories |
( |
xdgHandle * |
handle |
) |
|
Preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory.
- Parameters:
-
- Returns:
- A null-terminated list of directory strings.
char* xdgDataFind |
( |
const char * |
relativePath, |
|
|
xdgHandle * |
handle | |
|
) |
| | |
Find all existing data files corresponding to relativePath. Consider as performing
on every possible
filename
and returning the successful
filename
s.
- Parameters:
-
| relativePath | Path to scan for. |
| handle | Handle to data cache, initialized with xdgInitHandle(). |
- Returns:
- A sequence of null-terminated strings terminated by a double-null (empty string) and allocated using malloc(), e.g.:
"/etc/share\0/home/jdoe/.local\0"
const char* xdgDataHome |
( |
xdgHandle * |
handle |
) |
|
Base directory for user specific data files.
- Parameters:
-
- Returns:
- a path as described by the standards.
FILE* xdgDataOpen |
( |
const char * |
relativePath, |
|
|
const char * |
mode, |
|
|
xdgHandle * |
handle | |
|
) |
| | |
Open first possible data file corresponding to relativePath. Consider as performing
on every possible
filename
and returning the first successful
filename
or
NULL
.
- Parameters:
-
| relativePath | Path to scan for. |
| mode | Mode with which to attempt to open files (see fopen modes). |
| handle | Handle to data cache, initialized with xdgInitHandle(). |
- Returns:
- File pointer if successful else
NULL
. Client must use fclose
to close file.
Initialize a handle to an XDG data cache and initialize the cache. Use xdgWipeHandle() to free the handle.
- Returns:
- a pointer to the handle if initialization was successful, else 0
int xdgMakePath |
( |
const char * |
path, |
|
|
mode_t |
mode | |
|
) |
| | |
Create path by recursively creating directories. This utility function is not part of the XDG specification, but nevertheless useful in context of directory manipulation.
- Parameters:
-
| path | The path to be created. |
| mode | The permissions to use for created directories. This parameter is modified by the process's umask. For details, see mkdir(2)'s mode parameter. |
- Returns:
- Zero on success, -1 if an error occured (in which case errno will be set appropriately)
const char* const* xdgSearchableConfigDirectories |
( |
xdgHandle * |
handle |
) |
|
Preference-ordered set of base directories to search for configuration files with $XDG_CONFIG_HOME prepended. The base directory defined by $XDG_CONFIG_HOME is considered more important than any of the base directories defined by $XDG_CONFIG_DIRS.
- Parameters:
-
- Returns:
- A null-terminated list of directory strings.
const char* const* xdgSearchableDataDirectories |
( |
xdgHandle * |
handle |
) |
|
Preference-ordered set of base directories to search for data files with $XDG_DATA_HOME prepended. The base directory defined by $XDG_DATA_HOME is considered more important than any of the base directories defined by $XDG_DATA_DIRS.
- Parameters:
-
- Returns:
- A null-terminated list of directory strings.
Update the data cache. This should not be done frequently as it reallocates the cache. Even if updating the cache fails the handle remains valid and can be used to access XDG data as it was before xdgUpdateData() was called.
- Returns:
- 0 if update failed, non-0 if successful.
Wipe handle of XDG data cache. Wipe handle initialized using xdgInitHandle().