From 14c611ed7788fe68f5752ed29ab295a2f0e7c21e Mon Sep 17 00:00:00 2001 From: erw7 Date: Sun, 13 Oct 2019 17:34:08 +0900 Subject: 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 --- src/nvim/CMakeLists.txt | 1 + src/nvim/os/users.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'src') 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 #endif +#ifdef WIN32 +# include +#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; -- cgit