aboutsummaryrefslogtreecommitdiff
path: root/sandbox/envvar/envvar.c
blob: bbcb1c9f794ac3734040ebb5edf5ad0e3d51815a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	const char* pg_dbname = getenv("POSTGRES_DBNAME");
	const char* pg_host = getenv("POSTGRES_HOST");
	const char* pg_password = getenv("POSTGRES_PASSWORD");
	const char* pg_port = getenv("POSTGRES_PORT");
	const char* pg_user = getenv("POSTGRES_USER");

	printf("POSTGRES_DBNAME: %s\n", (pg_dbname != NULL) ? pg_dbname : "undefined");
	printf("POSTGRES_HOST: %s\n", (pg_host != NULL) ? pg_host : "undefined");
	printf("POSTGRES_PASSWORD: %s\n", (pg_password != NULL) ? pg_password : "undefined");
	printf("POSTGRES_PORT: %s\n", (pg_port != NULL) ? pg_port : "undefined");
	printf("POSTGRES_USER: %s\n", (pg_user != NULL) ? pg_user : "undefined");

	char *config = "host=%s port=%s user=%s password=%s dbname=%s sslmode=disable\n";

	sprintf(
		config,
		pg_host,
		pg_port,
		pg_user,
		pg_password,
		pg_dbname
	);

}