/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib/env.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-05-08 18:06:36 UTC
  • Revision ID: csa@suren.me-20150508180636-x3vsolbme4uot0ox
Prevent excessive calling of getenv by debugging code for better performance

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include "env.h"
 
4
 
 
5
 
 
6
static const char *pcilib_env_cache[PCILIB_MAX_ENV] = {0};
 
7
 
 
8
const char *pcilib_getenv(pcilib_env_t env, const char *var) {
 
9
    if (!pcilib_env_cache[env]) {
 
10
        const char *var_env = getenv(var);
 
11
        pcilib_env_cache[env] = var_env?var_env:(void*)-1;
 
12
        return var_env;
 
13
    }
 
14
 
 
15
    return (pcilib_env_cache[env] == (void*)-1)?NULL:pcilib_env_cache[env];
 
16
}
 
17