summaryrefslogtreecommitdiffstats
path: root/pcilib/env.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2015-05-08 20:06:36 +0200
committerSuren A. Chilingaryan <csa@suren.me>2015-05-08 20:06:36 +0200
commit79d9b2924d7b67ba08e022792adb92770f64e0c8 (patch)
treedc2ce5058978bfe88de1613291f21aa2ca7d9b0c /pcilib/env.c
parenta1889bc2f45b3d944652be6436569980f189922d (diff)
downloadpcitool-79d9b2924d7b67ba08e022792adb92770f64e0c8.tar.gz
pcitool-79d9b2924d7b67ba08e022792adb92770f64e0c8.tar.bz2
pcitool-79d9b2924d7b67ba08e022792adb92770f64e0c8.tar.xz
pcitool-79d9b2924d7b67ba08e022792adb92770f64e0c8.zip
Prevent excessive calling of getenv by debugging code for better performance
Diffstat (limited to 'pcilib/env.c')
-rw-r--r--pcilib/env.c17
1 files changed, 17 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#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];
+}
+