mirror of
https://github.com/neovim/neovim.git
synced 2025-10-13 21:36:05 +00:00
os_getenv, os_setenv: revert "widechar" impl
It's reported that the Windows widechar variants do automatically convert from the current codepage to UTF16, which is very helpful. So the "widechar" impls are a good direction. But libuv v1.12 does that for us, so the next commit will use that instead. ref #8398 ref #9267
This commit is contained in:
@@ -36,25 +36,8 @@
|
|||||||
const char *os_getenv(const char *name)
|
const char *os_getenv(const char *name)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
#if !defined(WIN32)
|
|
||||||
const char *e = getenv(name);
|
const char *e = getenv(name);
|
||||||
return e == NULL || *e == NUL ? NULL : e;
|
return e == NULL || *e == NUL ? NULL : e;
|
||||||
#else
|
|
||||||
wchar_t *wname;
|
|
||||||
utf8_to_utf16(name, &wname);
|
|
||||||
if (wname == NULL) {
|
|
||||||
xfree(wname);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
wchar_t *wvalue = _wgetenv(wname);
|
|
||||||
char *value;
|
|
||||||
int rv = utf16_to_utf8(wvalue, &value);
|
|
||||||
if (rv != 0 || *value == NUL) {
|
|
||||||
xfree(value);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return value; // TODO(jmk): this was allocated, but callers don't free it ...
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the environment variable, `name`, has been defined
|
/// Returns `true` if the environment variable, `name`, has been defined
|
||||||
@@ -72,21 +55,9 @@ int os_setenv(const char *name, const char *value, int overwrite)
|
|||||||
if (!overwrite && os_getenv(name) != NULL) {
|
if (!overwrite && os_getenv(name) != NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
wchar_t *wname;
|
int rv = (int)_putenv_s(name, value);
|
||||||
utf8_to_utf16(name, &wname);
|
|
||||||
if (wname == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
wchar_t *wvalue;
|
|
||||||
utf8_to_utf16(value, &wvalue);
|
|
||||||
if (wvalue == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
int rv = (int)_wputenv_s(wname, wvalue);
|
|
||||||
xfree(wname); // Unlike unix putenv(), we can free after _wputenv_s().
|
|
||||||
xfree(wvalue);
|
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
ELOG("_wputenv_s failed: %d: %s", rv, uv_strerror(rv));
|
ELOG("_putenv_s failed: %d: %s", rv, uv_strerror(rv));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -45,15 +45,15 @@ describe(':let', function()
|
|||||||
]=])
|
]=])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("sets environment variables", function()
|
it("multibyte environment variables", function()
|
||||||
local multibyte_multiline = [[\p* .ม .ม .ม .ม่ .ม่ .ม่ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ ֹֻ
|
command("let $NVIM_TEST = 'AìaB'")
|
||||||
.ֹֻ .ֹֻ .ֹֻ ֹֻ ֹֻ ֹֻ .ֹֻ .ֹֻ .ֹֻ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ
|
eq('AìaB', eval('$NVIM_TEST'))
|
||||||
.ֹֻ .ֹֻ .ֹֻ a a a ca ca ca à à à]]
|
command("let $NVIM_TEST = 'AaあB'")
|
||||||
command("let $NVIM_TEST1 = 'AìaB'")
|
eq('AaあB', eval('$NVIM_TEST'))
|
||||||
command("let $NVIM_TEST2 = 'AaあB'")
|
local mbyte = [[\p* .ม .ม .ม .ม่ .ม่ .ม่ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ ֹֻ
|
||||||
command("let $NVIM_TEST3 = '"..multibyte_multiline.."'")
|
.ֹֻ .ֹֻ .ֹֻ ֹֻ ֹֻ ֹֻ .ֹֻ .ֹֻ .ֹֻ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ
|
||||||
eq('AìaB', eval('$NVIM_TEST1'))
|
.ֹֻ .ֹֻ .ֹֻ a a a ca ca ca à à à]]
|
||||||
eq('AaあB', eval('$NVIM_TEST2'))
|
command("let $NVIM_TEST = '"..mbyte.."'")
|
||||||
eq(multibyte_multiline, eval('$NVIM_TEST3'))
|
eq(mbyte, eval('$NVIM_TEST'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user