std1.0.0-beta-7 SafeC docs

Module path

#include <std/path.h> source

Path strings

Pure string manipulation of file system paths: nothing here touches the file system (see std/dir.h for that). Every function returns a fresh String (free it), and accepts '/' as the separator everywhere; on Windows targets '' is a separator too. Results always use '/' (Windows APIs accept it).

struct String p = path_join("site", "../dist/index.html"); // "site/../dist/index.html"
struct String n = path_normalize(p.as_ptr());              // "dist/index.html"
struct String e = path_ext("a/b.tar.gz");                  // "gz"

Functions

path_is_sep1 if 'c' separates path components on this target ('/', and '' on Windows).
path_is_absolute1 for "/x", and on Windows also "\x", "C:\x" and "C:/x".
path_join'a' + '/' + 'b' with exactly one separator between them; when 'b' is absolute the result is just 'b' (like Python's os.path.join). An empty side yields the other.
path_dirnameEverything before the last component: "a/b/c" -> "a/b", "c" -> "", "/c" -> "/", "a/b/" -> "a". Trailing separators are ignored.
path_basenameThe last component: "a/b.c" -> "b.c", "a/b/" -> "b", "/" -> "".
path_extThe last component's extension, without the dot: "a/b.tar.gz" -> "gz", "b" -> "", ".bashrc" -> "" (a leading dot names a file, not an extension).
path_stemThe last component without its extension: "a/b.tar.gz" -> "b.tar", ".bashrc" -> ".bashrc".
path_normalizeLexically normalized: repeated separators collapsed, "." components dropped, "x/.." pairs removed (leading ".." kept on a relative path, dropped at the root of an absolute one), no trailing separator. "" and "." normalize to ".".
path_relativeThe path that leads from directory 'from' to 'to', both normalized first: path_relative("a/b", "a/c/d") -> "../c/d"; the same path -> ".". Both must be relative, or both absolute (otherwise 'to' is returned, normalized).