1 //
2 // SetEnvironmentVariableA.cpp
3 //
4 //      Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // Definition of __acrt_SetEnvironmentVariableA.
7 //
8 
9 #include <corecrt_internal_win32_buffer.h>
10 
11 BOOL __cdecl __acrt_SetEnvironmentVariableA(
12     LPCSTR const lpName,
13     LPCSTR const lpValue
14     )
15 {
16     __crt_internal_win32_buffer<wchar_t> wide_name;
17     __crt_internal_win32_buffer<wchar_t> wide_value;
18 
19     errno_t const cvt1 = __acrt_mbs_to_wcs_cp(
20         lpName,
21         wide_name,
22         __acrt_get_utf8_acp_compatibility_codepage()
23         );
24 
25     if (cvt1 != 0) {
26         return FALSE;
27     }
28 
29     errno_t const cvt2 = __acrt_mbs_to_wcs_cp(
30         lpValue,
31         wide_value,
32         __acrt_get_utf8_acp_compatibility_codepage()
33         );
34 
35     if (cvt2 != 0) {
36         return FALSE;
37     }
38 
39     return ::SetEnvironmentVariableW(wide_name.data(), wide_value.data());
40 }
41