|
33 | 33 |
|
34 | 34 | namespace cuda::experimental::stf |
35 | 35 | { |
36 | | -// Hack setenv on Windows |
37 | | -#if _CCCL_COMPILER(MSVC) |
38 | | -/** |
39 | | - * @brief Sets an environment variable, mimicking the behavior of `std::setenv` on Windows. |
40 | | - * |
41 | | - * This function attempts to set the value of the environment variable `name` to `value`. |
42 | | - * If `overwrite` is 0 and the variable already exists, the function does nothing. |
43 | | - * |
44 | | - * @param name The name of the environment variable. |
45 | | - * @param value The value to assign to the environment variable. |
46 | | - * @param overwrite If non-zero, the function will overwrite the existing value of the variable. |
47 | | - * @return 0 on success, or -1 on failure (invalid input or memory allocation failure). |
48 | | - * @note This function is designed for MSVC, which lacks a standard `setenv` function. |
49 | | - */ |
50 | | -inline int setenv(const char* name, const char* value, int overwrite) |
51 | | -{ |
52 | | - if (!name || !value || !name[0]) |
53 | | - { |
54 | | - // Invalid input: name or value is null, or name is an empty string |
55 | | - return -1; |
56 | | - } |
57 | | - |
58 | | - // Check if the variable already exists and if overwrite is allowed |
59 | | - if (!overwrite && ::std::getenv(name) != nullptr) |
60 | | - { |
61 | | - return 0; // Variable exists, and we're not allowed to overwrite it |
62 | | - } |
63 | | - |
64 | | - // Construct the string in the form "NAME=VALUE" |
65 | | - auto env_var = ::std::string(name) + "=" + value; |
66 | | - |
67 | | - // Use _putenv to set the environment variable in MSVC |
68 | | - if (_putenv(env_var.c_str()) != 0) |
69 | | - { |
70 | | - return -1; // _putenv failed |
71 | | - } |
72 | | - |
73 | | - return 0; // Success |
74 | | -} |
75 | | -#endif |
76 | | - |
77 | 36 | #ifndef _CCCL_DOXYGEN_INVOKED // FIXME Doxygen is lost with decltype(auto) |
78 | 37 | /** |
79 | 38 | * @brief Custom move function that performs checks on the argument type. |
|
0 commit comments