My Kernel v0.1.0
Libpath

Path handling library. More...

Collaboration diagram for Libpath:

Modules

 Path walking
 Walking along a path.
 

Data Structures

struct  libpath_path
 Safer wrapper around a string symbolizing a path. More...
 

Macros

#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.
 

Functions

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...
 

Detailed Description

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.

Macro Definition Documentation

◆ LIBPATH_SEPARATOR

#define LIBPATH_SEPARATOR   '/'

Anything else is considered as a regular character.

Function Documentation

◆ 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
parentThe string inside which the parent's path is stored
pathThe original path
sizeThe 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.