Intel® OpenMP* Runtime Library
 All Classes Functions Variables Typedefs Enumerations Enumerator Modules Pages
kmp_environment.h
1 /*
2  * kmp_environment.h -- Handle environment varoiables OS-independently.
3  */
4 
5 /* <copyright>
6  Copyright (c) 1997-2015 Intel Corporation. All Rights Reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions
10  are met:
11 
12  * Redistributions of source code must retain the above copyright
13  notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  notice, this list of conditions and the following disclaimer in the
16  documentation and/or other materials provided with the distribution.
17  * Neither the name of Intel Corporation nor the names of its
18  contributors may be used to endorse or promote products derived
19  from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 </copyright> */
34 
35 #ifndef KMP_ENVIRONMENT_H
36 #define KMP_ENVIRONMENT_H
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 // Return a copy of the value of environment variable or NULL if the variable does not exist.
43 // *Note*: Returned pointed *must* be freed after use with __kmp_env_free().
44 char * __kmp_env_get( char const * name );
45 void __kmp_env_free( char const * * value );
46 
47 // Return 1 if the environment variable exists or 0 if does not exist.
48 int __kmp_env_exists( char const * name );
49 
50 // Set the environment variable.
51 void __kmp_env_set( char const * name, char const * value, int overwrite );
52 
53 // Unset (remove) environment variable.
54 void __kmp_env_unset( char const * name );
55 
56 
57 // -------------------------------------------------------------------------------------------------
58 // Working with environment blocks.
59 // -------------------------------------------------------------------------------------------------
60 
61 /*
62  kmp_env_blk_t is read-only collection of environment variables (or environment-like). Usage:
63 
64  kmp_env_blk_t block;
65  __kmp_env_blk_init( & block, NULL ); // Initialize block from process environment.
66  // or
67  __kmp_env_blk_init( & block, "KMP_WARNING=1|KMP_AFFINITY=none" ); // from string.
68  __kmp_env_blk_sort( & block ); // Optionally, sort list.
69  for ( i = 0; i < block.count; ++ i ) {
70  // Process block.vars[ i ].name and block.vars[ i ].value...
71  }; // for i
72  __kmp_env_block_free( & block );
73 */
74 
75 struct __kmp_env_var {
76  char const * name;
77  char const * value;
78 };
79 typedef struct __kmp_env_var kmp_env_var_t;
80 
81 struct __kmp_env_blk {
82  char const * bulk;
83  kmp_env_var_t const * vars;
84  int count;
85 };
86 typedef struct __kmp_env_blk kmp_env_blk_t;
87 
88 void __kmp_env_blk_init( kmp_env_blk_t * block, char const * bulk );
89 void __kmp_env_blk_free( kmp_env_blk_t * block );
90 void __kmp_env_blk_sort( kmp_env_blk_t * block );
91 char const * __kmp_env_blk_var( kmp_env_blk_t * block, char const * name );
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif // KMP_ENVIRONMENT_H
98 
99 // end of file //
100