|
stc
|
Namespaces | |
| namespace | colour |
| Module for ANSI colours. | |
| namespace | FntParser |
| namespace | math |
| namespace | StdFix |
| namespace | string |
| namespace | testutil |
| namespace | Unix |
Classes | |
| class | FileLock |
| class | PasswordIO |
Enumerations | |
| enum class | StreamType { STDOUT , STDERR , OTHER } |
Functions | |
| void | setEnv (const char *name, const char *value, bool replace=true) |
| std::string | getEnv (const char *name, const std::string &fail="") |
| std::filesystem::path | expandUserPath (const std::string &inputPath) |
| std::filesystem::path | getHome () |
| std::string | syscommand (const std::string &command, int *codeOutput=nullptr) |
| std::string | syscommand (std::vector< const char * > command, int *codeOutput=nullptr) |
| void | syscommandNoCapture (std::vector< const char * > command, int *codeOutput=nullptr) |
| std::optional< std::string > | getHostname () |
| bool | isStreamTTY (StreamType type=StreamType::STDOUT) |
| std::string | executablePath () |
| template<typename CharT > | |
| static constexpr StreamType | getOutputStreamType (std::basic_ostream< CharT > &ss) |
| template<typename CharT > | |
| bool | isCppStreamTTY (std::basic_ostream< CharT > &ss) |
|
strong |
|
inline |
Wrapper around _NSGetExecutablePath (Crapplebook ShitOS), GetModuleFileNameA (Microsoft "Excessively verbose for the shits and giggles" Windows), and /proc/self/exe (everything else)
|
inline |
Expands a user path (AKA a path starting with ~), independently of the OS. Returns the path unmodified if the path isn't a user path.
This requires several OS-specific calls (specifically between Windows and UNIX, from what I can tell. There's not much of a difference in this area between for an instance Linux and Mac. Special implementation requirements will be taken when we get to a point where it's needed)
|
inline |
Wrapper around various secure getenv methods. Falls back to std::getenv with a warning if none is available.
|
inline |
Returns the user's home directory.
Note that the windows implementation is wank, and may not be as reliable as the UNIX implementation.
|
inline |
Returns the hostname of the machine.
|
staticconstexpr |
Determines the StreamType for a given input stream. This is primarily intended as a utility function for isCppStreamTTY, but can be used standalone
For now, it does not handle application-level redirects of std::cout, only OS-level redirects. This means that if you redirect the internal buffer, the function still detects it as stdout. This may or may not be a feature depending on your point of view, so for the time being, it's up to you to determine how to handle such redirects.
|
inline |
|
inline |
Utility wrapper around isatty (UNIX)/_isatty (Windows). Can be used to determine if a stream type is a TTY or redirected to a file or similar.
You probably don't want to use this function directly; use isCppStreamTTY instead.
| type | A StreamType. Because of how low-level this operates, this function only tells you what the OS redirects stdout to. Useful if you have control of the streams. |
|
inline |
Wrapper around setenv/unsetenv (UNIX) and _putenv_s (Windows)
| name | The name of the environment variable |
| value | The value of the environment variable. If null, the environment variable is deleted. |
| replace | Whether or not to replace the environment variable if it exists. Only respected on UNIX. true is the only cross-platform-compatible value. |
|
inline |
std::system alternative that returns the output from the subprocess.
WARNING: This function spawns a shell under the hood, as it uses popen. DO NOT pass user input to this command; it is a security vulnerability, and distraction & rm -rf / as user input will ruin your day at best. This command, like std::system, requires significant input cleaning before use. If you're dealing with user input, use syscommand(std::vector<const char*>, int*) instead.
|
inline |
Lower-level command that does the same thing syscommand(std::string, int*) does, but using a vector for arguments instead of a single string.
This is in theory slightly safer than using a string directly, provided the command you invoke is safe. Unless you do something dumb, all arguments are passed directly to the command (provided as the first argument of the vector), so unless the command you're invoking can do something unsafe, it's safe from && as input.
There's still lots of ways user input can and will fuck you over, so do be careful.
Not currently supported on Windows due to CreatePipe being a pain to work with.
|
inline |
Same as syscommand(std::vector<const char*>, int*), but doesn't return output. This is intended as a hardened std::system.