AxlPath — Path Manipulation
See AxlSys — System Utilities for an overview of all utility modules including path manipulation.
Header: <axl/axl-path.h>
API Reference
Functions
-
char *axl_path_get_basename(const char *path)
Return the filename portion of a path.
axl-path.h:
Path manipulation: basename, dirname, extension, join, resolve. Handles both ‘/’ (Unix) and ‘' (UEFI) path separators. All allocated results are freed with axl_free().
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:
AXL_OK on success, AXL_ERR on error (NULL args, buffer too small, or “..” underflow past root).
-
char *axl_path_companion(const char *anchor, const char *name)
Build a path to a file alongside another (the “companion” pattern: load
jedec.json5from the directory holding the binary that just started running, etc.).Equivalent to axl_path_join with the dirname of
anchoras the directory portion. Returns justname(joined with “.”/empty) ifanchorhas no directory component. NULL-safe.Caller frees with axl_free.
char *cfg = axl_path_companion(axl_app_argv0(), "jedec.json5"); // load cfg if non-NULL
- Parameters:
anchor – reference path (e.g. argv[0])
name – filename to place beside
anchor
- Returns:
newly allocated path, or NULL if either argument is NULL or allocation fails.
-
char *axl_resolve_data_file(const char *override_path, const char *name)
Resolve a sidecar data file by trying override → companion → cwd.
Standard lookup order for tools that ship optional sidecar JSON (jedec ID DB, vendor lists, board configs, etc.):
If
override_pathis non-NULL and the file exists, use it.Companion path beside the running binary. Two anchors are tried in order: a. axl_app_image_path — canonical FILEPATH from EFI_LOADED_IMAGE_PROTOCOL. Reliable regardless of how the shell invoked the binary (basename vs full path, cwd-rooted vs absolute). b. axl_app_argv0 — the shell-supplied invocation string. Fallback for synthetic load contexts where the image path is unavailable.
nameas-is (current working directory).
Returns the first path that exists. Caller must axl_free() the returned string. The check uses axl_file_info, so the file must be readable at lookup time.
char *p = axl_resolve_data_file( axl_args_get_string(a, "jedec-file"), // CLI override (may be NULL) "jedec.json5" ); if (p != NULL) { load_table(p); axl_free(p); }
- Parameters:
override_path – optional explicit path (may be NULL)
name – filename to resolve
- Returns:
newly allocated path, or NULL if no candidate exists.
-
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:
AXL_OK on success, AXL_ERR 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:
AXL_OK on success, AXL_ERR on error.