kmp_environment.h 2.2 KB

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