| 1 | #ifndef AWS_COMMON_ENVIRONMENT_H |
| 2 | #define AWS_COMMON_ENVIRONMENT_H |
| 3 | |
| 4 | /** |
| 5 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 6 | * SPDX-License-Identifier: Apache-2.0. |
| 7 | */ |
| 8 | |
| 9 | #include <aws/common/common.h> |
| 10 | |
| 11 | AWS_PUSH_SANE_WARNING_LEVEL |
| 12 | |
| 13 | struct aws_string; |
| 14 | |
| 15 | /* |
| 16 | * Simple shims to the appropriate platform calls for environment variable manipulation. |
| 17 | * |
| 18 | * Not thread safe to use set/unset unsynced with get. Set/unset only used in unit tests. |
| 19 | */ |
| 20 | AWS_EXTERN_C_BEGIN |
| 21 | |
| 22 | /* |
| 23 | * Get the value of an environment variable. If the variable is not set, the output string will be set to NULL. |
| 24 | * Not thread-safe |
| 25 | */ |
| 26 | AWS_COMMON_API |
| 27 | struct aws_string *aws_get_env(struct aws_allocator *allocator, const char *name); |
| 28 | |
| 29 | /* |
| 30 | * Get the value of an environment variable. If the variable is not set or is empty, the output string will be set to |
| 31 | * NULL. Not thread-safe |
| 32 | */ |
| 33 | AWS_COMMON_API |
| 34 | struct aws_string *aws_get_env_nonempty(struct aws_allocator *allocator, const char *name); |
| 35 | |
| 36 | /* |
| 37 | * *DEPRECATED* |
| 38 | * Please use the `aws_get_env` or `aws_get_env_nonempty` instead. |
| 39 | * Get the value of an environment variable. If the variable is not set, the output string will be set to NULL. |
| 40 | * Not thread-safe |
| 41 | */ |
| 42 | AWS_COMMON_API |
| 43 | int aws_get_environment_value( |
| 44 | struct aws_allocator *allocator, |
| 45 | const struct aws_string *variable_name, |
| 46 | struct aws_string **value_out); |
| 47 | |
| 48 | /* |
| 49 | * Set the value of an environment variable. On Windows, setting a variable to the empty string will actually unset it. |
| 50 | * Not thread-safe |
| 51 | */ |
| 52 | AWS_COMMON_API |
| 53 | int aws_set_environment_value(const struct aws_string *variable_name, const struct aws_string *value); |
| 54 | |
| 55 | /* |
| 56 | * Unset an environment variable. |
| 57 | * Not thread-safe |
| 58 | */ |
| 59 | AWS_COMMON_API |
| 60 | int aws_unset_environment_value(const struct aws_string *variable_name); |
| 61 | |
| 62 | AWS_EXTERN_C_END |
| 63 | AWS_POP_SANE_WARNING_LEVEL |
| 64 | |
| 65 | #endif /* AWS_COMMON_ENVIRONMENT_H */ |