diff options
author | Stefan Hoffmann <stefan991@gmail.com> | 2014-03-06 23:20:29 +0100 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-13 17:18:44 -0300 |
commit | ce31410c7953a19421a2f2df2d3e6654601da930 (patch) | |
tree | d07b8af604b81c6323ba5dc405fcdd7f9397abf6 /src | |
parent | 6fd9f090fc66c3ba38dc07ea6c982c3124735f32 (diff) | |
download | rneovim-ce31410c7953a19421a2f2df2d3e6654601da930.tar.gz rneovim-ce31410c7953a19421a2f2df2d3e6654601da930.tar.bz2 rneovim-ce31410c7953a19421a2f2df2d3e6654601da930.zip |
moved mch_get_user_name() and mch_get_uname() into os/users.c
Diffstat (limited to 'src')
-rw-r--r-- | src/memline.c | 4 | ||||
-rw-r--r-- | src/misc2.c | 2 | ||||
-rw-r--r-- | src/os/os.h | 2 | ||||
-rw-r--r-- | src/os/users.c | 29 | ||||
-rw-r--r-- | src/os_unix.c | 28 | ||||
-rw-r--r-- | src/os_unix.h | 2 |
6 files changed, 34 insertions, 33 deletions
diff --git a/src/memline.c b/src/memline.c index 463aeb4b58..2126b4109a 100644 --- a/src/memline.c +++ b/src/memline.c @@ -1739,7 +1739,7 @@ static time_t swapfile_info(char_u *fname) time_t x = (time_t)0; char *p; #ifdef UNIX - char_u uname[B0_UNAME_SIZE]; + char uname[B0_UNAME_SIZE]; #endif /* print the swap file date */ @@ -1748,7 +1748,7 @@ static time_t swapfile_info(char_u *fname) /* print name of owner of the file */ if (mch_get_uname(st.st_uid, uname, B0_UNAME_SIZE) == OK) { MSG_PUTS(_(" owned by: ")); - msg_outtrans(uname); + msg_outtrans((char_u *)uname); MSG_PUTS(_(" dated: ")); } else #endif diff --git a/src/misc2.c b/src/misc2.c index dd3c7363da..d97393e699 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -1886,7 +1886,7 @@ int vim_chdir(char_u *new_dir) int get_user_name(char_u *buf, int len) { if (username == NULL) { - if (mch_get_user_name(buf, len) == FAIL) + if (mch_get_user_name((char *)buf, len) == FAIL) return FAIL; username = vim_strsave(buf); } else diff --git a/src/os/os.h b/src/os/os.h index 87323fb025..d94f8bdc57 100644 --- a/src/os/os.h +++ b/src/os/os.h @@ -14,5 +14,7 @@ const char *mch_getenv(const char *name); int mch_setenv(const char *name, const char *value, int overwrite); char *mch_getenvname_at_index(size_t index); int mch_get_usernames(garray_T *usernames); +int mch_get_user_name(char *s, size_t len); +int mch_get_uname(uid_t uid, char *s, size_t len); #endif diff --git a/src/os/users.c b/src/os/users.c index b392118f1b..fa8971be61 100644 --- a/src/os/users.c +++ b/src/os/users.c @@ -55,3 +55,32 @@ int mch_get_usernames(garray_T *users) return OK; } +/* + * Insert user name in s[len]. + * Return OK if a name found. + */ +int mch_get_user_name(char *s, size_t len) +{ + return mch_get_uname(getuid(), s, len); +} + +/* + * Insert user name for "uid" in s[len]. + * Return OK if a name found. + * If the name is not found, write the uid into s[len] and return FAIL. + */ +int mch_get_uname(uid_t uid, char *s, size_t len) +{ +#if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) + struct passwd *pw; + + if ((pw = getpwuid(uid)) != NULL + && pw->pw_name != NULL && *(pw->pw_name) != NUL) { + vim_strncpy((char_u *)s, (char_u *)pw->pw_name, len - 1); + return OK; + } +#endif + snprintf(s, len, "%d", (int)uid); + return FAIL; // a number is not a name +} + diff --git a/src/os_unix.c b/src/os_unix.c index 3bbe056cc6..9ed034f4c1 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1078,34 +1078,6 @@ int vim_is_fastterm(char_u *name) } /* - * Insert user name in s[len]. - * Return OK if a name found. - */ -int mch_get_user_name(char_u *s, int len) -{ - return mch_get_uname(getuid(), s, len); -} - -/* - * Insert user name for "uid" in s[len]. - * Return OK if a name found. - */ -int mch_get_uname(uid_t uid, char_u *s, int len) -{ -#if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) - struct passwd *pw; - - if ((pw = getpwuid(uid)) != NULL - && pw->pw_name != NULL && *(pw->pw_name) != NUL) { - vim_strncpy(s, (char_u *)pw->pw_name, len - 1); - return OK; - } -#endif - sprintf((char *)s, "%d", (int)uid); /* assumes s is long enough */ - return FAIL; /* a number is not a name */ -} - -/* * Insert host name is s[len]. */ diff --git a/src/os_unix.h b/src/os_unix.h index 606237ee80..4db402c1e8 100644 --- a/src/os_unix.h +++ b/src/os_unix.h @@ -24,8 +24,6 @@ int use_xterm_mouse(void); int vim_is_iris(char_u *name); int vim_is_vt300(char_u *name); int vim_is_fastterm(char_u *name); -int mch_get_user_name(char_u *s, int len); -int mch_get_uname(uid_t uid, char_u *s, int len); void mch_get_host_name(char_u *s, int len); long mch_get_pid(void); void slash_adjust(char_u *p); |