picceler
Loading...
Searching...
No Matches
picceler::utils Namespace Reference

Functions

std::string expandTilde (const std::string &inputPath)

Function Documentation

◆ expandTilde()

std::string picceler::utils::expandTilde ( const std::string & inputPath)

Expands a leading tilde in a filesystem path to the current user's home directory.

On POSIX systems, this uses the HOME environment variable when available and falls back to getpwuid(getuid()) if HOME is not set. On Windows, it uses the USERPROFILE environment variable, or HOMEDRIVE + HOMEPATH if USERPROFILE is not available.

If the input does not begin with '~', or if the home directory cannot be determined (e.g., required environment variables are unset and system calls fail), the original inputPath is returned unchanged.

Parameters
inputPathPath string that may start with '~' to refer to the user's home.
Returns
A string where a leading '~' has been replaced by the user's home directory, or the original inputPath if no expansion is performed.