#include #include #include int main(int argc, char *argv[]) { char pg_dbname[128] = {0}; char pg_host[128] = {0}; char pg_password[128] = {0}; char pg_port[8] = {0}; char pg_user[128] = {0}; const char* env; env = getenv("POSTGRES_DBNAME"); if (env != NULL) { strncpy(pg_dbname, env, sizeof(pg_dbname)); } env = getenv("POSTGRES_HOST"); if (env != NULL) { strncpy(pg_host, env, sizeof(pg_host)); } env = getenv("POSTGRES_PASSWORD"); if (env != NULL) { strncpy(pg_password, env, sizeof(pg_password)); } env = getenv("POSTGRES_PORT"); if (env != NULL) { strncpy(pg_port, env, sizeof(pg_port)); } env = getenv("POSTGRES_USER"); if (env != NULL) { strncpy(pg_user, env, sizeof(pg_user)); } char *config_fmt = "host=%s port=%s user=%s password=%s dbname=%s sslmode=disable"; printf(config_fmt, pg_host, pg_port, pg_user, pg_password, pg_dbname); printf("\n"); char sqladdr[2048]; snprintf( sqladdr, sizeof(sqladdr), config_fmt, pg_host, pg_port, pg_user, pg_password, pg_dbname ); printf("%s", sqladdr); printf("\n"); }