diff options
author | erw7 <erw7.github@gmail.com> | 2019-10-13 17:34:08 +0900 |
---|---|---|
committer | erw7 <erw7.github@gmail.com> | 2019-10-13 17:34:08 +0900 |
commit | 14c611ed7788fe68f5752ed29ab295a2f0e7c21e (patch) | |
tree | f5b37aadab691ea707c189797022141002e95e43 | |
parent | 9af0fe529d2d91640e4d3388ab9f28159553f14c (diff) | |
download | rneovim-14c611ed7788fe68f5752ed29ab295a2f0e7c21e.tar.gz rneovim-14c611ed7788fe68f5752ed29ab295a2f0e7c21e.tar.bz2 rneovim-14c611ed7788fe68f5752ed29ab295a2f0e7c21e.zip |
vim-patch 8.1.0084: user name completion does not work on MS-Windows
Problem: User name completion does not work on MS-Windows.
Solution: Use NetUserEnum() to get user names. (Yasuhiro Matsumoto)
https://github.com/vim/vim/commit/828c3d70833a0689cc07581f2a67d06430675da5
-rw-r--r-- | src/nvim/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/nvim/os/users.c | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index a64944ab0d..b00ac866b7 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -419,6 +419,7 @@ if(Iconv_LIBRARIES) endif() if(WIN32) + list(APPEND NVIM_LINK_LIBRARIES netapi32) list(APPEND NVIM_LINK_LIBRARIES ${WINPTY_LIBRARIES}) endif() diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index c6463c2c92..b24232b680 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -13,6 +13,9 @@ #ifdef HAVE_PWD_H # include <pwd.h> #endif +#ifdef WIN32 +# include <lm.h> +#endif // Initialize users garray and fill it with os usernames. // Return Ok for success, FAIL for failure. @@ -34,6 +37,26 @@ int os_get_usernames(garray_T *users) } } endpwent(); +# elif defined(WIN32) + { + DWORD nusers = 0, ntotal = 0, i; + PUSER_INFO_0 uinfo; + + if (NetUserEnum(NULL, 0, 0, (LPBYTE *)&uinfo, MAX_PREFERRED_LENGTH, + &nusers, &ntotal, NULL) == NERR_Success) { + for (i = 0; i < nusers; i++) { + char *user; + int conversion_result = utf16_to_utf8(uinfo[i].usri0_name, -1, &user); + if (conversion_result != 0) { + EMSG2("utf16_to_utf8 failed: %d", conversion_result); + break; + } + GA_APPEND(char *, users, user); + } + + NetApiBufferFree(uinfo); + } + } # endif return OK; |