Path handling library.
More...
|
| #define | LIBPATH_SEPARATOR '/' |
| | Path separator. More...
|
| |
|
#define | NEW_PATH(_path, _len) |
| | Initialize a new path.
|
| |
|
#define | NEW_DYNAMIC_PATH(_path) NEW_PATH((_path), strlen((_path))) |
| | Dynamically create a path using libc's strlen function If you already know the string's length, use NEW_PATH instead.
|
| |
|
|
static bool | path_is_absolute (const path_t *path) |
| | Check whether a path is an absolute one.
|
| |
|
static bool | path_is_empty (const path_t *path) |
| | Check whether a path is empty.
|
| |
| ssize_t | path_load_parent (char *parent, const path_t *path, size_t size) |
| | Store the raw path of path's parent inside a string. More...
|
| |
Libpath
Description
This library allows us to parse and walk along a path (backward and forward). It does so by splitting a path into different segments, around the '/' separator. Once a segment has been parsed, you can retrieve the previous and next ones, thus effectively walking along the original path (see Path walking for more details).
- Note
- This library does not create a path nor modify the original string, and simply uses a safer simple string wrapper as well as substrings to find its way around the original raw string.
◆ LIBPATH_SEPARATOR
| #define LIBPATH_SEPARATOR '/' |
Anything else is considered as a regular character.
◆ path_load_parent()
| ssize_t path_load_parent |
( |
char * |
parent, |
|
|
const path_t * |
path, |
|
|
size_t |
size |
|
) |
| |
The string must be allocated beforehand, and be large enough to store the parent's raw path (including the NULL terminator).
- Parameters
-
| parent | The string inside which the parent's path is stored |
| path | The original path |
| size | The size of the parent buffer |
- Returns
- The length of the parent path, -1 if the buffer wasn't large enough or if the path is empty.