00001 /* 00002 * kmp_environment.h -- Handle environment varoiables OS-independently. 00003 * $Revision: 42061 $ 00004 * $Date: 2013-02-28 16:36:24 -0600 (Thu, 28 Feb 2013) $ 00005 */ 00006 00007 /* <copyright> 00008 Copyright (c) 1997-2013 Intel Corporation. All Rights Reserved. 00009 00010 Redistribution and use in source and binary forms, with or without 00011 modification, are permitted provided that the following conditions 00012 are met: 00013 00014 * Redistributions of source code must retain the above copyright 00015 notice, this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright 00017 notice, this list of conditions and the following disclaimer in the 00018 documentation and/or other materials provided with the distribution. 00019 * Neither the name of Intel Corporation nor the names of its 00020 contributors may be used to endorse or promote products derived 00021 from this software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00026 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00027 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00031 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 00035 00036 ------------------------------------------------------------------------ 00037 00038 Portions of this software are protected under the following patents: 00039 U.S. Patent 5,812,852 00040 U.S. Patent 6,792,599 00041 U.S. Patent 7,069,556 00042 U.S. Patent 7,328,433 00043 U.S. Patent 7,500,242 00044 00045 </copyright> */ 00046 00047 #ifndef KMP_ENVIRONMENT_H 00048 #define KMP_ENVIRONMENT_H 00049 00050 #ifdef __cplusplus 00051 extern "C" { 00052 #endif 00053 00054 // Return a copy of the value of environment variable or NULL if the variable does not exist. 00055 // *Note*: Returned pointed *must* be freed after use with __kmp_env_free(). 00056 char * __kmp_env_get( char const * name ); 00057 void __kmp_env_free( char const * * value ); 00058 00059 // Return 1 if the environment variable exists or 0 if does not exist. 00060 int __kmp_env_exists( char const * name ); 00061 00062 // Set the environment variable. 00063 void __kmp_env_set( char const * name, char const * value, int overwrite ); 00064 00065 // Unset (remove) environment variable. 00066 void __kmp_env_unset( char const * name ); 00067 00068 00069 // ------------------------------------------------------------------------------------------------- 00070 // Working with environment blocks. 00071 // ------------------------------------------------------------------------------------------------- 00072 00073 /* 00074 kmp_env_blk_t is read-only collection of environment variables (or environment-like). Usage: 00075 00076 kmp_env_blk_t block; 00077 __kmp_env_blk_init( & block, NULL ); // Initialize block from process environment. 00078 // or 00079 __kmp_env_blk_init( & block, "KMP_WARNING=1|KMP_AFFINITY=none" ); // from string. 00080 __kmp_env_blk_sort( & block ); // Optionally, sort list. 00081 for ( i = 0; i < block.count; ++ i ) { 00082 // Process block.vars[ i ].name and block.vars[ i ].value... 00083 }; // for i 00084 __kmp_env_block_free( & block ); 00085 */ 00086 00087 struct __kmp_env_var { 00088 char const * name; 00089 char const * value; 00090 }; 00091 typedef struct __kmp_env_var kmp_env_var_t; 00092 00093 struct __kmp_env_blk { 00094 char const * bulk; 00095 kmp_env_var_t const * vars; 00096 int count; 00097 }; 00098 typedef struct __kmp_env_blk kmp_env_blk_t; 00099 00100 void __kmp_env_blk_init( kmp_env_blk_t * block, char const * bulk ); 00101 void __kmp_env_blk_free( kmp_env_blk_t * block ); 00102 void __kmp_env_blk_sort( kmp_env_blk_t * block ); 00103 char const * __kmp_env_blk_var( kmp_env_blk_t * block, char const * name ); 00104 00105 #ifdef __cplusplus 00106 } 00107 #endif 00108 00109 #endif // KMP_ENVIRONMENT_H 00110 00111 // end of file // 00112