Introduction
This library provides a simple loader for .env files, allowing you to read key/value pairs, query them, and optionally inject them into the process environment.
Usage
- Call
env_load("path/to/.env") to load environment variables.
- Use
env_get("KEY") to retrieve values.
- Optionally, call
env_inject_all(1) to inject variables into the system environment.
- Free memory with
env_free().
Public API
The main functions exposed by this library are:
Internal Members
For developers, the following internal members are available:
Example
int main() {
const char* val =
env_get(
"MY_KEY");
}
void env_free(void)
Free all memory used by loaded .env variables.
Definition env.c:200
int env_load(const char *path)
Load environment variables from a .env file.
Definition env.c:120
int env_inject_all(int overwrite)
Inject all loaded .env variables into the process environment.
Definition env.c:189
const char * env_get(const char *key)
Get value of an environment variable loaded from .env.
Definition env.c:155