|
CX Framework
Cross-platform C utility framework
|
Functions | |
| bool | envGet (string *out, strref name) |
| bool | envSet (strref name, strref val) |
| bool | envUnset (strref name) |
| bool | envEnum (hashtable *out) |
| bool | envExists (strref name) |
Reads and changes the environment variables of the running process.
A variable set to an empty string still exists. Removing one completely is a separate call, envUnset(), because "set to empty" and "not set at all" are different states and a program reading the variable can tell them apart.
Windows matches variable names without regard to case, so PATH and Path are the same variable there. Unix matches them exactly, so they are two different variables. cx does not hide this difference, because the programs and libraries that read these variables do not hide it either. envEnum() builds its table to match the platform, so looking a name up in that table gives the same answer the platform itself would give.
cx locks its own environment calls, so envGet(), envSet(), envUnset() and envEnum() are safe to call from several threads at once.
That lock does not cover calls cx does not make. On Unix, changing the environment while another thread reads it with a plain getenv() – from the C library, or from any other library in the process – can crash, and cx cannot prevent that from outside. Set the variables a program needs during startup, before it starts any threads, and leave the environment alone after that. Windows does not have this problem.
| bool envEnum | ( | hashtable * | out | ) |
Reads the entire environment into a hashtable of name to value.
This initializes the table itself, so pass an uninitialized hashtable. Destroy it with htDestroy() when finished.
| out | Receives a new string-to-string table |
Example:
|
inline |
Checks whether an environment variable is set.
| name | Variable name |
Example:
Definition at line 114 of file env.h.
References envGet(), and strDestroy().
| bool envGet | ( | string * | out, |
| strref | name | ||
| ) |
Reads an environment variable.
| out | Receives the value, or is set to empty if the variable is not set |
| name | Variable name |
Example:
Referenced by envExists().
| bool envSet | ( | strref | name, |
| strref | val | ||
| ) |
Sets an environment variable, creating it or replacing whatever value it had.
| name | Variable name; must not be empty and must not contain '=' |
| val | Value to set; NULL or empty gives the variable an empty value |
Example: