removed get_user_name() and replaced calls with mch_get_user_name()

This commit is contained in:
Stefan Hoffmann
2014-03-06 23:53:15 +01:00
committed by Thiago de Arruda
parent ce31410c79
commit ad77ff53d3
4 changed files with 10 additions and 30 deletions

View File

@@ -31,6 +31,7 @@
#include "syntax.h" #include "syntax.h"
#include "term.h" #include "term.h"
#include "ui.h" #include "ui.h"
#include "os/os.h"
/* /*
* To implement printing on a platform, the following functions must be * To implement printing on a platform, the following functions must be
@@ -2500,8 +2501,9 @@ int mch_print_begin(prt_settings_T *psettings)
*/ */
prt_dsc_start(); prt_dsc_start();
prt_dsc_textline("Title", (char *)psettings->jobname); prt_dsc_textline("Title", (char *)psettings->jobname);
if (!get_user_name((char_u *)buffer, 256)) if (mch_get_user_name(buffer, 256) == FAIL) {
STRCPY(buffer, "Unknown"); STRCPY(buffer, "Unknown");
}
prt_dsc_textline("For", buffer); prt_dsc_textline("For", buffer);
prt_dsc_textline("Creator", VIM_VERSION_LONG); prt_dsc_textline("Creator", VIM_VERSION_LONG);
/* Note: to ensure Clean8bit I don't think we can use LC_TIME */ /* Note: to ensure Clean8bit I don't think we can use LC_TIME */

View File

@@ -343,7 +343,7 @@ int ml_open(buf_T *buf)
b0p->b0_dirty = buf->b_changed ? B0_DIRTY : 0; b0p->b0_dirty = buf->b_changed ? B0_DIRTY : 0;
b0p->b0_flags = get_fileformat(buf) + 1; b0p->b0_flags = get_fileformat(buf) + 1;
set_b0_fname(b0p, buf); set_b0_fname(b0p, buf);
(void)get_user_name(b0p->b0_uname, B0_UNAME_SIZE); (void)mch_get_user_name((char *)b0p->b0_uname, B0_UNAME_SIZE);
b0p->b0_uname[B0_UNAME_SIZE - 1] = NUL; b0p->b0_uname[B0_UNAME_SIZE - 1] = NUL;
mch_get_host_name(b0p->b0_hname, B0_HNAME_SIZE); mch_get_host_name(b0p->b0_hname, B0_HNAME_SIZE);
b0p->b0_hname[B0_HNAME_SIZE - 1] = NUL; b0p->b0_hname[B0_HNAME_SIZE - 1] = NUL;
@@ -833,8 +833,7 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
if (buf->b_ffname == NULL) if (buf->b_ffname == NULL)
b0p->b0_fname[0] = NUL; b0p->b0_fname[0] = NUL;
else { else {
size_t flen, ulen; char uname[B0_UNAME_SIZE];
char_u uname[B0_UNAME_SIZE];
/* /*
* For a file under the home directory of the current user, we try to * For a file under the home directory of the current user, we try to
@@ -846,13 +845,14 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
home_replace(NULL, buf->b_ffname, b0p->b0_fname, home_replace(NULL, buf->b_ffname, b0p->b0_fname,
B0_FNAME_SIZE_CRYPT, TRUE); B0_FNAME_SIZE_CRYPT, TRUE);
if (b0p->b0_fname[0] == '~') { if (b0p->b0_fname[0] == '~') {
flen = STRLEN(b0p->b0_fname);
/* If there is no user name or it is too long, don't use "~/" */ /* If there is no user name or it is too long, don't use "~/" */
if (get_user_name(uname, B0_UNAME_SIZE) == FAIL int retval = mch_get_user_name(uname, B0_UNAME_SIZE);
|| (ulen = STRLEN(uname)) + flen > B0_FNAME_SIZE_CRYPT - 1) size_t ulen = STRLEN(uname);
size_t flen = STRLEN(b0p->b0_fname);
if (retval == FAIL || ulen + flen > B0_FNAME_SIZE_CRYPT - 1) {
vim_strncpy(b0p->b0_fname, buf->b_ffname, vim_strncpy(b0p->b0_fname, buf->b_ffname,
B0_FNAME_SIZE_CRYPT - 1); B0_FNAME_SIZE_CRYPT - 1);
else { } else {
mch_memmove(b0p->b0_fname + ulen + 1, b0p->b0_fname + 1, flen); mch_memmove(b0p->b0_fname + ulen + 1, b0p->b0_fname + 1, flen);
mch_memmove(b0p->b0_fname + 1, uname, ulen); mch_memmove(b0p->b0_fname + 1, uname, ulen);
} }

View File

@@ -47,8 +47,6 @@
#include "window.h" #include "window.h"
#include "os/os.h" #include "os/os.h"
static char_u *username = NULL; /* cached result of mch_get_user_name() */
static int coladvance2(pos_T *pos, int addspaces, int finetune, static int coladvance2(pos_T *pos, int addspaces, int finetune,
colnr_T wcol); colnr_T wcol);
@@ -935,7 +933,6 @@ void free_all_mem(void) {
clear_sb_text(); /* free any scrollback text */ clear_sb_text(); /* free any scrollback text */
/* Free some global vars. */ /* Free some global vars. */
vim_free(username);
vim_free(last_cmdline); vim_free(last_cmdline);
vim_free(new_last_cmdline); vim_free(new_last_cmdline);
set_keep_msg(NULL, 0); set_keep_msg(NULL, 0);
@@ -1876,24 +1873,6 @@ int vim_chdir(char_u *new_dir)
return r; return r;
} }
/*
* Get user name from machine-specific function.
* Returns the user name in "buf[len]".
* Some systems are quite slow in obtaining the user name (Windows NT), thus
* cache the result.
* Returns OK or FAIL.
*/
int get_user_name(char_u *buf, int len)
{
if (username == NULL) {
if (mch_get_user_name((char *)buf, len) == FAIL)
return FAIL;
username = vim_strsave(buf);
} else
vim_strncpy(buf, username, len - 1);
return OK;
}
#ifndef HAVE_QSORT #ifndef HAVE_QSORT
/* /*
* Our own qsort(), for systems that don't have it. * Our own qsort(), for systems that don't have it.

View File

@@ -66,7 +66,6 @@ int same_directory(char_u *f1, char_u *f2);
int vim_chdirfile(char_u *fname); int vim_chdirfile(char_u *fname);
int illegal_slash(char *name); int illegal_slash(char *name);
int vim_chdir(char_u *new_dir); int vim_chdir(char_u *new_dir);
int get_user_name(char_u *buf, int len);
void sort_strings(char_u **files, int count); void sort_strings(char_u **files, int count);
int pathcmp(const char *p, const char *q, int maxlen); int pathcmp(const char *p, const char *q, int maxlen);
int filewritable(char_u *fname); int filewritable(char_u *fname);