diff options
author | Chris Robinson <[email protected]> | 2019-10-01 22:15:40 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-10-01 22:15:40 -0700 |
commit | 28d54efe72323cc6791d0ee3d15accff7765e853 (patch) | |
tree | b9ea28f5a460f4db1d4feaf51089933c1a5d70fc | |
parent | a0a55d300fef56c4422482ae8aeaabaf2a3c4178 (diff) |
Use al::getenv to get the router env vars
-rw-r--r-- | router/router.cpp | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/router/router.cpp b/router/router.cpp index e9173a22..88e75b67 100644 --- a/router/router.cpp +++ b/router/router.cpp @@ -3,18 +3,20 @@ #include "router.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - #include <algorithm> +#include <cstdio> +#include <cstdlib> +#include <cstring> #include "AL/alc.h" #include "AL/al.h" + #include "almalloc.h" +#include "strutils.h" #include "version.h" + std::vector<DriverIface> DriverList; thread_local DriverIface *ThreadCtxDriver; @@ -27,51 +29,47 @@ static void LoadDriverList(void); BOOL APIENTRY DllMain(HINSTANCE, DWORD reason, void*) { - const char *str; - switch(reason) { - case DLL_PROCESS_ATTACH: - LogFile = stderr; - str = getenv("ALROUTER_LOGFILE"); - if(str && *str != '\0') - { - FILE *f = fopen(str, "w"); - if(f == nullptr) - ERR("Could not open log file: %s\n", str); - else - LogFile = f; - } - str = getenv("ALROUTER_LOGLEVEL"); - if(str && *str != '\0') - { - char *end = nullptr; - long l = strtol(str, &end, 0); - if(!end || *end != '\0') - ERR("Invalid log level value: %s\n", str); - else if(l < LogLevel_None || l > LogLevel_Trace) - ERR("Log level out of range: %s\n", str); - else - LogLevel = static_cast<enum LogLevel>(l); - } - TRACE("Initializing router v0.1-%s %s\n", ALSOFT_GIT_COMMIT_HASH, ALSOFT_GIT_BRANCH); - LoadDriverList(); + case DLL_PROCESS_ATTACH: + LogFile = stderr; + if(auto logfname = al::getenv("ALROUTER_LOGFILE")) + { + FILE *f = fopen(logfname->c_str(), "w"); + if(f == nullptr) + ERR("Could not open log file: %s\n", logfname->c_str()); + else + LogFile = f; + } + if(auto loglev = al::getenv("ALROUTER_LOGLEVEL")) + { + char *end = nullptr; + long l = strtol(loglev->c_str(), &end, 0); + if(!end || *end != '\0') + ERR("Invalid log level value: %s\n", loglev->c_str()); + else if(l < LogLevel_None || l > LogLevel_Trace) + ERR("Log level out of range: %s\n", loglev->c_str()); + else + LogLevel = static_cast<enum LogLevel>(l); + } + TRACE("Initializing router v0.1-%s %s\n", ALSOFT_GIT_COMMIT_HASH, ALSOFT_GIT_BRANCH); + LoadDriverList(); - break; + break; - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; - case DLL_PROCESS_DETACH: - DriverList.clear(); + case DLL_PROCESS_DETACH: + DriverList.clear(); - if(LogFile && LogFile != stderr) - fclose(LogFile); - LogFile = nullptr; + if(LogFile && LogFile != stderr) + fclose(LogFile); + LogFile = nullptr; - break; + break; } return TRUE; } |