Mentions légales du service

Skip to content
Snippets Groups Projects
Commit a0b07b8c authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Add functionnalities to play with environement variables

parent 2ff248ed
No related branches found
No related tags found
1 merge request!316Add function to set limits min and max of submitted tasks
...@@ -31,6 +31,88 @@ ...@@ -31,6 +31,88 @@
extern "C" { extern "C" {
#endif #endif
/*
* Get environment variable
*/
#if defined(CHAMELEON_OS_WINDOWS)
static inline int
chameleon_setenv( const char *var, const char *value, int overwrite ) {
return !(SetEnvironmentVariable( var, value ));
}
static inline char *
chameleon_getenv( const char *var ) {
char *str;
int len = 512;
int rc;
str = (char*)malloc(len * sizeof(char));
rc = GetEnvironmentVariable(var, str, len);
if (rc == 0) {
free(str);
str = NULL;
}
return str;
}
static inline void
chameleon_cleanenv( char *str ) {
if (str != NULL) free(str);
}
#else /* Other OS systems */
static inline int
chameleon_setenv( const char *var, const char *value, int overwrite ) {
return setenv( var, value, overwrite );
}
static inline char *
chameleon_getenv( const char *var ) {
return getenv( var );
}
static inline void
chameleon_cleanenv( char *str ) {
(void)str;
}
#endif
static inline int
chameleon_env_is_set_to(char * str, char * value) {
char * val;
if ( (val = chameleon_getenv(str)) &&
!strcmp(val, value))
return 1;
return 0;
}
static inline int
chameleon_env_is_on(char * str) {
return chameleon_env_is_set_to(str, "1");
}
static inline int
chameleon_env_is_off(char * str) {
return chameleon_env_is_set_to(str, "0");
}
static inline int
chameleon_getenv_get_value_int(char * string, int default_value) {
long int ret;
char *str = chameleon_getenv(string);
if (str == NULL) return default_value;
if ( sscanf( str, "%ld", &ret ) != 1 ) {
perror("sscanf");
return default_value;
}
return (int)ret;
}
/** /**
* Internal routines * Internal routines
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment