swr: [rasterizer core] utility function for getenv
authorTim Rowley <timothy.o.rowley@intel.com>
Wed, 4 May 2016 16:40:10 +0000 (10:40 -0600)
committerTim Rowley <timothy.o.rowley@intel.com>
Thu, 19 May 2016 21:25:48 +0000 (16:25 -0500)
Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/core/utils.h

index e3c534dd8515d590339b0fd82d801df250f0302f..1c4780a527610bf35316da651f2491182df504f5 100644 (file)
@@ -866,3 +866,20 @@ struct TemplateArgUnroller
     }
 };
 
+//////////////////////////////////////////////////////////////////////////
+/// Helper used to get an environment variable
+//////////////////////////////////////////////////////////////////////////
+static INLINE std::string GetEnv(const std::string& variableName)
+{
+    std::string output;
+#if defined(_WIN32)
+    DWORD valueSize = GetEnvironmentVariableA(variableName.c_str(), nullptr, 0);
+    if (!valueSize) return output;
+    output.resize(valueSize - 1); // valueSize includes null, output.resize() does not
+    GetEnvironmentVariableA(variableName.c_str(), &output[0], valueSize);
+#else
+    output = getenv(variableName.c_str());
+#endif
+
+    return output;
+}
\ No newline at end of file