AxlPath – Path Manipulation
Path manipulation: basename, dirname, extension, join, resolve. Handles
both / (Unix) and \ (UEFI) path separators. All allocated results
are freed with axl_free().
Header: <axl/axl-path.h>
Overview
UEFI uses backslash (\) as the path separator, while most developers
are familiar with forward slash (/). AXL accepts both and normalizes
internally. Paths typically start with a volume name: fs0:/path/to/file.
AXL_AUTO_FREE char *base = axl_path_get_basename("fs0:/logs/app.log");
// base = "app.log"
AXL_AUTO_FREE char *dir = axl_path_get_dirname("fs0:/logs/app.log");
// dir = "fs0:/logs"
AXL_AUTO_FREE char *ext = axl_path_get_extension("app.log");
// ext = "log"
AXL_AUTO_FREE char *full = axl_path_join("fs0:/data", "output.json");
// full = "fs0:/data/output.json"
// Resolve relative paths
char resolved[256];
axl_path_resolve("fs0:/app", "../config/app.cfg",
resolved, sizeof(resolved));
// resolved = "fs0:/config/app.cfg"
API Reference
Functions
-
char *axl_path_get_basename(const char *path)
Return the filename portion of a path.
Returns everything after the last separator (‘/’ or ‘'). Returns a copy of
pathitself if no separator is found. Caller frees with axl_free(). NULL-safe.- Parameters:
path – file path, or NULL
- Returns:
newly allocated string, or NULL if
pathis NULL or allocation fails.
-
char *axl_path_get_dirname(const char *path)
Return the directory portion of a path.
Returns everything before the last separator. Returns “.” if no separator is found. Caller frees with axl_free(). NULL-safe.
- Parameters:
path – file path, or NULL
- Returns:
newly allocated string, or NULL if
pathis NULL or allocation fails.
-
const char *axl_path_extension(const char *path)
Return the file extension from a path.
Returns a pointer to the extension after the last dot in the basename portion of
path. Ignores leading dots (e.g. “.bashrc” has no extension). NULL-safe.- Parameters:
path – file path, or NULL
- Returns:
pointer into
path(not allocated), or NULL ifpathis NULL or has no extension.
-
char *axl_path_join(const char *dir, const char *name)
Join a directory and filename with ‘/’.
Handles a trailing separator on
dir. Caller frees with axl_free(). NULL-safe: returns NULL if either argument is NULL.- Parameters:
dir – directory path, or NULL
name – filename to append, or NULL
- Returns:
newly allocated path, or NULL on failure.
-
int axl_path_resolve(const char *base, const char *relative, char *out, size_t size)
Resolve a relative path against a base directory.
Combines
baseandrelative, normalizing “.” and “..” components. Both ‘/’ and ‘' are recognized as separators. Ifrelativeis absolute (starts with ‘/’ or ‘'),baseis ignored. The output always uses ‘/’ separators.- Parameters:
base – base directory path
relative – relative path to resolve
out – output buffer
size – output buffer size
- Returns:
0 on success, -1 on error (NULL args, buffer too small, or “..” underflow past root).
-
int axl_path_build_uefi(const char *volume, const char *subpath, char *out, size_t size)
Build a UEFI-style path with volume prefix.
Writes “VOLUME:SUBPATH” into
out, converting forward slashes to backslashes. For example, axl_path_build_uefi(“fs0”, “/dir/file”) produces “fs0:\dir\file”.- Parameters:
volume – volume name (e.g. “fs0”)
subpath – subpath (forward slashes OK)
out – output buffer
size – output buffer size
- Returns:
0 on success, -1 on error (NULL args or buffer too small).
-
char *axl_get_current_dir(void)
Get the current working directory.
Returns a UTF-8 copy. Caller frees with axl_free().
- Returns:
current directory path, or NULL on error.
-
int axl_chdir(const char *path)
Change the current working directory.
- Parameters:
path – directory path (UTF-8)
- Returns:
0 on success, -1 on error.