diff options
-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; |