From 79d9b2924d7b67ba08e022792adb92770f64e0c8 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Fri, 8 May 2015 20:06:36 +0200 Subject: Prevent excessive calling of getenv by debugging code for better performance --- pcilib/env.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pcilib/env.c (limited to 'pcilib/env.c') diff --git a/pcilib/env.c b/pcilib/env.c new file mode 100644 index 0000000..16444db --- /dev/null +++ b/pcilib/env.c @@ -0,0 +1,17 @@ +#include +#include +#include "env.h" + + +static const char *pcilib_env_cache[PCILIB_MAX_ENV] = {0}; + +const char *pcilib_getenv(pcilib_env_t env, const char *var) { + if (!pcilib_env_cache[env]) { + const char *var_env = getenv(var); + pcilib_env_cache[env] = var_env?var_env:(void*)-1; + return var_env; + } + + return (pcilib_env_cache[env] == (void*)-1)?NULL:pcilib_env_cache[env]; +} + -- cgit v1.2.3