aboutsummaryrefslogtreecommitdiff
path: root/src/os/users.c
diff options
context:
space:
mode:
authorStefan Hoffmann <stefan991@gmail.com>2014-03-06 21:55:17 +0100
committerThiago de Arruda <tpadilha84@gmail.com>2014-03-13 17:18:43 -0300
commit6fd9f090fc66c3ba38dc07ea6c982c3124735f32 (patch)
tree052b7d267c182c9975fb2b3e837cef66b0a166b4 /src/os/users.c
parentf6ace9962d95eb12236083871154c1501f02c556 (diff)
downloadrneovim-6fd9f090fc66c3ba38dc07ea6c982c3124735f32.tar.gz
rneovim-6fd9f090fc66c3ba38dc07ea6c982c3124735f32.tar.bz2
rneovim-6fd9f090fc66c3ba38dc07ea6c982c3124735f32.zip
refactored logic from init_users() into mch_get_usernames()
Diffstat (limited to 'src/os/users.c')
-rw-r--r--src/os/users.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/os/users.c b/src/os/users.c
new file mode 100644
index 0000000000..b392118f1b
--- /dev/null
+++ b/src/os/users.c
@@ -0,0 +1,57 @@
+/* vi:set ts=2 sts=2 sw=2:
+ *
+ * VIM - Vi IMproved by Bram Moolenaar
+ *
+ * Do ":help uganda" in Vim to read copying and usage conditions.
+ * Do ":help credits" in Vim to see a list of people who contributed.
+ * See README.txt for an overview of the Vim source code.
+ */
+
+/*
+ * users.c -- operating system user information
+ */
+
+#include <uv.h>
+
+#include "os.h"
+#include "../garray.h"
+#include "../misc2.h"
+#ifdef HAVE_PWD_H
+# include <pwd.h>
+#endif
+
+/*
+ * Initialize users garray and fill it with os usernames.
+ * Return Ok for success, FAIL for failure.
+ */
+int mch_get_usernames(garray_T *users)
+{
+ if (users == NULL) {
+ return FALSE;
+ }
+ ga_init2(users, sizeof(char *), 20);
+
+# if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H)
+ char *user;
+ struct passwd *pw;
+
+ setpwent();
+ while ((pw = getpwent()) != NULL) {
+ /* pw->pw_name shouldn't be NULL but just in case... */
+ if (pw->pw_name != NULL) {
+ if (ga_grow(users, 1) == FAIL) {
+ return FAIL;
+ }
+ user = (char *)vim_strsave((char_u*)pw->pw_name);
+ if (user == NULL) {
+ return FAIL;
+ }
+ ((char **)(users->ga_data))[users->ga_len++] = user;
+ }
+ }
+ endpwent();
+# endif
+
+ return OK;
+}
+