Both path::home() and the xdg accessors read an environment variable and branch on whether it is present. An empty string is present, so it wins over the fallback.
home()
src/platform/path.cpp:31 reads HOME through environment::value(), which returns std::optional<std::string>. With HOME="" set, that optional holds "" and has_value() is true, so .or_else() never runs and getpwuid() is never consulted. home() returns path{""}.
xdg
src/platform/xdg.cpp:14 and the three sibling accessors do the same with XDG_CONFIG_HOME and friends. With XDG_CONFIG_HOME="", config_home() returns "myapp" — a relative path in the working directory rather than an absolute one.
The XDG Base Directory specification is explicit here: a variable set to an empty value is to be treated the same as one that is unset.
Effect
A caller who passes the result to path::mkdir() creates directories under the current working directory instead of under the user's home.
Both
path::home()and thexdgaccessors read an environment variable and branch on whether it is present. An empty string is present, so it wins over the fallback.home()
src/platform/path.cpp:31readsHOMEthroughenvironment::value(), which returnsstd::optional<std::string>. WithHOME=""set, that optional holds""andhas_value()is true, so.or_else()never runs andgetpwuid()is never consulted.home()returnspath{""}.xdg
src/platform/xdg.cpp:14and the three sibling accessors do the same withXDG_CONFIG_HOMEand friends. WithXDG_CONFIG_HOME="",config_home()returns"myapp"— a relative path in the working directory rather than an absolute one.The XDG Base Directory specification is explicit here: a variable set to an empty value is to be treated the same as one that is unset.
Effect
A caller who passes the result to
path::mkdir()creates directories under the current working directory instead of under the user's home.