1 /* 2 * kmp_environment.h -- Handle environment variables OS-independently. 3 */ 4 5 //===----------------------------------------------------------------------===// 6 // 7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 8 // See https://llvm.org/LICENSE.txt for license information. 9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef KMP_ENVIRONMENT_H 14 #define KMP_ENVIRONMENT_H 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 // Return a copy of the value of environment variable or NULL if the variable 21 // does not exist. 22 // *Note*: Returned pointed *must* be freed after use with __kmp_env_free(). 23 char *__kmp_env_get(char const *name); 24 void __kmp_env_free(char const **value); 25 26 // Return 1 if the environment variable exists or 0 if does not exist. 27 int __kmp_env_exists(char const *name); 28 29 // Set the environment variable. 30 void __kmp_env_set(char const *name, char const *value, int overwrite); 31 32 // Unset (remove) environment variable. 33 void __kmp_env_unset(char const *name); 34 35 // ----------------------------------------------------------------------------- 36 // Working with environment blocks. 37 38 /* kmp_env_blk_t is read-only collection of environment variables (or 39 environment-like). Usage: 40 41 kmp_env_blk_t block; 42 __kmp_env_blk_init( & block, NULL ); // Initialize block from process 43 // environment. 44 // or 45 __kmp_env_blk_init( & block, "KMP_WARNING=1|KMP_AFFINITY=none" ); // from string 46 __kmp_env_blk_sort( & block ); // Optionally, sort list. 47 for ( i = 0; i < block.count; ++ i ) { 48 // Process block.vars[ i ].name and block.vars[ i ].value... 49 } 50 __kmp_env_block_free( & block ); 51 */ 52 53 struct __kmp_env_var { 54 char *name; 55 char *value; 56 }; 57 typedef struct __kmp_env_var kmp_env_var_t; 58 59 struct __kmp_env_blk { 60 char *bulk; 61 kmp_env_var_t *vars; 62 int count; 63 }; 64 typedef struct __kmp_env_blk kmp_env_blk_t; 65 66 void __kmp_env_blk_init(kmp_env_blk_t *block, char const *bulk); 67 void __kmp_env_blk_free(kmp_env_blk_t *block); 68 void __kmp_env_blk_sort(kmp_env_blk_t *block); 69 char const *__kmp_env_blk_var(kmp_env_blk_t *block, char const *name); 70 71 #ifdef __cplusplus 72 } 73 #endif 74 75 #endif // KMP_ENVIRONMENT_H 76 77 // end of file // 78