.env Loader
Loading...
Searching...
No Matches
env.h File Reference

Go to the source code of this file.

Functions

int env_load (const char *path)
 Load environment variables from a .env file.
 
const char * env_get (const char *key)
 Get value of a loaded environment variable.
 
int env_inject_all (int overwrite)
 Inject all loaded environment variables into the process environment.
 
void env_free (void)
 Free all loaded environment variable data.
 

Function Documentation

◆ env_free()

void env_free ( void )

Free all loaded environment variable data.

Free all loaded environment variable data.

◆ env_get()

const char * env_get ( const char * key)

Get value of a loaded environment variable.

Parameters
keyEnvironment variable key.
Returns
Value string or NULL if not found.

Get value of a loaded environment variable.

Parameters
keyEnvironment variable key.
Returns
Value string or NULL if not found.

◆ env_inject_all()

int env_inject_all ( int overwrite)

Inject all loaded environment variables into the process environment.

Parameters
overwriteNonzero to overwrite existing system variables.
Returns
0 on success, -1 on failure.

Inject all loaded environment variables into the process environment.

Parameters
overwriteNonzero to overwrite existing system variables.
Returns
0 on success, -1 on error.

◆ env_load()

int env_load ( const char * path)

Load environment variables from a .env file.

Parameters
pathPath to .env file.
Returns
0 on success, -1 on failure.

Lines beginning with # are treated as comments and ignored. Keys and values are separated by =.

Parameters
pathPath to .env file.
Returns
0 on success, -1 on error (file not found, allocation failure, etc.).