Skip to content

Commit c5c6beb

Browse files
committed
Merge branch 'vim'
2 parents 6e441ac + 3fd86dc commit c5c6beb

File tree

8 files changed

+348
-40
lines changed

8 files changed

+348
-40
lines changed

.hgtags

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,3 +2730,12 @@ f6247eaf4e1d556f782321890d725663f74babe6 v7-4-004
27302730
3640cf4c0d4b6e5687bb7a31678fab70c88ed94b v7-4-005
27312731
2374a05efe20287d55bd824689a41becc7662505 v7-4-006
27322732
4fe1dfc7014e57b4beb5a01c9e94357265d19a92 v7-4-007
2733+
b04bdb2c5fce70a278d26c477debb65a388da0ca v7-4-008
2734+
8b5d80861c5e0403ea9f54ddddce2752a463c8a5 v7-4-009
2735+
bb358cc41d920983629ace62bcf26decbf06cab4 v7-4-010
2736+
54e66395831c1a58b4a9804e7884e505842157e8 v7-4-011
2737+
8e28c23e482c5b3c8296d8022271822886793456 v7-4-012
2738+
07737d3aa81725672796cbc9a010d63414ab6fea v7-4-013
2739+
9801d06e7b4ccdcd02cf40bee34eaaada0ca0409 v7-4-014
2740+
a7478f9f2551e95bff138cd658f7a86ced804ab1 v7-4-015
2741+
8d5cd0ec3e7183a289f9bac41d3981307cdc1fac v7-4-016

src/eval.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12143,6 +12143,9 @@ f_has(argvars, rettv)
1214312143
#ifndef CASE_INSENSITIVE_FILENAME
1214412144
"fname_case",
1214512145
#endif
12146+
#ifdef HAVE_ACL
12147+
"acl",
12148+
#endif
1214612149
#ifdef FEAT_ARABIC
1214712150
"arabic",
1214812151
#endif
@@ -12558,7 +12561,12 @@ f_has(argvars, rettv)
1255812561
"xfontset",
1255912562
#endif
1256012563
#ifdef FEAT_XPM_W32
12561-
"xpm_w32",
12564+
"xpm",
12565+
"xpm_w32", /* for backward compatibility */
12566+
#else
12567+
# if defined(HAVE_XPM)
12568+
"xpm",
12569+
# endif
1256212570
#endif
1256312571
#ifdef USE_XSMP
1256412572
"xsmp",
@@ -14312,18 +14320,23 @@ f_mkdir(argvars, rettv)
1431214320
return;
1431314321

1431414322
dir = get_tv_string_buf(&argvars[0], buf);
14315-
if (*gettail(dir) == NUL)
14316-
/* remove trailing slashes */
14317-
*gettail_sep(dir) = NUL;
14318-
14319-
if (argvars[1].v_type != VAR_UNKNOWN)
14323+
if (*dir == NUL)
14324+
rettv->vval.v_number = FAIL;
14325+
else
1432014326
{
14321-
if (argvars[2].v_type != VAR_UNKNOWN)
14322-
prot = get_tv_number_chk(&argvars[2], NULL);
14323-
if (prot != -1 && STRCMP(get_tv_string(&argvars[1]), "p") == 0)
14324-
mkdir_recurse(dir, prot);
14327+
if (*gettail(dir) == NUL)
14328+
/* remove trailing slashes */
14329+
*gettail_sep(dir) = NUL;
14330+
14331+
if (argvars[1].v_type != VAR_UNKNOWN)
14332+
{
14333+
if (argvars[2].v_type != VAR_UNKNOWN)
14334+
prot = get_tv_number_chk(&argvars[2], NULL);
14335+
if (prot != -1 && STRCMP(get_tv_string(&argvars[1]), "p") == 0)
14336+
mkdir_recurse(dir, prot);
14337+
}
14338+
rettv->vval.v_number = prot == -1 ? FAIL : vim_mkdir_emsg(dir, prot);
1432514339
}
14326-
rettv->vval.v_number = prot == -1 ? FAIL : vim_mkdir_emsg(dir, prot);
1432714340
}
1432814341
#endif
1432914342

src/fileio.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,13 @@ readfile(fname, sfname, from, lines_to_skip, lines_to_read, eap, flags)
428428
}
429429
}
430430

431-
#ifdef UNIX
432-
/*
433-
* On Unix it is possible to read a directory, so we have to
434-
* check for it before the mch_open().
435-
*/
436431
if (!read_stdin && !read_buffer)
437432
{
433+
#ifdef UNIX
434+
/*
435+
* On Unix it is possible to read a directory, so we have to
436+
* check for it before the mch_open().
437+
*/
438438
perm = mch_getperm(fname);
439439
if (perm >= 0 && !S_ISREG(perm) /* not a regular file ... */
440440
# ifdef S_ISFIFO
@@ -457,8 +457,8 @@ readfile(fname, sfname, from, lines_to_skip, lines_to_read, eap, flags)
457457
msg_scroll = msg_save;
458458
return FAIL;
459459
}
460-
461-
# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
460+
#endif
461+
#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
462462
/*
463463
* MS-Windows allows opening a device, but we will probably get stuck
464464
* trying to read it.
@@ -470,9 +470,8 @@ readfile(fname, sfname, from, lines_to_skip, lines_to_read, eap, flags)
470470
msg_scroll = msg_save;
471471
return FAIL;
472472
}
473-
# endif
474-
}
475473
#endif
474+
}
476475

477476
/* Set default or forced 'fileformat' and 'binary'. */
478477
set_file_options(set_options, eap);
@@ -2926,9 +2925,14 @@ check_for_cryptkey(cryptkey, ptr, sizep, filesizep, newfile, fname, did_ask)
29262925
int *did_ask; /* flag: whether already asked for key */
29272926
{
29282927
int method = crypt_method_from_magic((char *)ptr, *sizep);
2928+
int b_p_ro = curbuf->b_p_ro;
29292929

29302930
if (method >= 0)
29312931
{
2932+
/* Mark the buffer as read-only until the decryption has taken place.
2933+
* Avoids accidentally overwriting the file with garbage. */
2934+
curbuf->b_p_ro = TRUE;
2935+
29322936
set_crypt_method(curbuf, method);
29332937
if (method > 0)
29342938
(void)blowfish_self_test();
@@ -2977,6 +2981,8 @@ check_for_cryptkey(cryptkey, ptr, sizep, filesizep, newfile, fname, did_ask)
29772981
*sizep -= CRYPT_MAGIC_LEN + salt_len + seed_len;
29782982
mch_memmove(ptr, ptr + CRYPT_MAGIC_LEN + salt_len + seed_len,
29792983
(size_t)*sizep);
2984+
/* Restore the read-only flag. */
2985+
curbuf->b_p_ro = b_p_ro;
29802986
}
29812987
}
29822988
/* When starting to edit a new file which does not have encryption, clear

src/os_mswin.c

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,22 @@ mch_FullName(
456456
int
457457
mch_isFullName(char_u *fname)
458458
{
459+
#ifdef FEAT_MBYTE
460+
/* WinNT and later can use _MAX_PATH wide characters for a pathname, which
461+
* means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is
462+
* UTF-8. */
463+
char szName[_MAX_PATH * 3 + 1];
464+
#else
459465
char szName[_MAX_PATH + 1];
466+
#endif
460467

461468
/* A name like "d:/foo" and "//server/share" is absolute */
462469
if ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\'))
463470
|| (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\')))
464471
return TRUE;
465472

466473
/* A name that can't be made absolute probably isn't absolute. */
467-
if (mch_FullName(fname, szName, _MAX_PATH, FALSE) == FAIL)
474+
if (mch_FullName(fname, szName, sizeof(szName) - 1, FALSE) == FAIL)
468475
return FALSE;
469476

470477
return pathcmp(fname, szName, -1) == 0;
@@ -498,10 +505,17 @@ slash_adjust(p)
498505
int
499506
vim_stat(const char *name, struct stat *stp)
500507
{
508+
#ifdef FEAT_MBYTE
509+
/* WinNT and later can use _MAX_PATH wide characters for a pathname, which
510+
* means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is
511+
* UTF-8. */
512+
char buf[_MAX_PATH * 3 + 1];
513+
#else
501514
char buf[_MAX_PATH + 1];
515+
#endif
502516
char *p;
503517

504-
vim_strncpy((char_u *)buf, (char_u *)name, _MAX_PATH);
518+
vim_strncpy((char_u *)buf, (char_u *)name, sizeof(buf) - 1);
505519
p = buf + strlen(buf);
506520
if (p > buf)
507521
mb_ptr_back(buf, p);
@@ -1761,9 +1775,13 @@ mch_resolve_shortcut(char_u *fname)
17611775
IPersistFile *ppf = NULL;
17621776
OLECHAR wsz[MAX_PATH];
17631777
WIN32_FIND_DATA ffd; // we get those free of charge
1764-
TCHAR buf[MAX_PATH]; // could have simply reused 'wsz'...
1778+
CHAR buf[MAX_PATH]; // could have simply reused 'wsz'...
17651779
char_u *rfname = NULL;
17661780
int len;
1781+
# ifdef FEAT_MBYTE
1782+
IShellLinkW *pslw = NULL;
1783+
WIN32_FIND_DATAW ffdw; // we get those free of charge
1784+
# endif
17671785

17681786
/* Check if the file name ends in ".lnk". Avoid calling
17691787
* CoCreateInstance(), it's quite slow. */
@@ -1775,44 +1793,92 @@ mch_resolve_shortcut(char_u *fname)
17751793

17761794
CoInitialize(NULL);
17771795

1796+
# ifdef FEAT_MBYTE
1797+
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
1798+
{
1799+
// create a link manager object and request its interface
1800+
hr = CoCreateInstance(
1801+
&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
1802+
&IID_IShellLinkW, (void**)&pslw);
1803+
if (hr == S_OK)
1804+
{
1805+
WCHAR *p = enc_to_utf16(fname, NULL);
1806+
1807+
if (p != NULL)
1808+
{
1809+
// Get a pointer to the IPersistFile interface.
1810+
hr = pslw->lpVtbl->QueryInterface(
1811+
pslw, &IID_IPersistFile, (void**)&ppf);
1812+
if (hr != S_OK)
1813+
goto shortcut_errorw;
1814+
1815+
// "load" the name and resolve the link
1816+
hr = ppf->lpVtbl->Load(ppf, p, STGM_READ);
1817+
if (hr != S_OK)
1818+
goto shortcut_errorw;
1819+
# if 0 // This makes Vim wait a long time if the target does not exist.
1820+
hr = pslw->lpVtbl->Resolve(pslw, NULL, SLR_NO_UI);
1821+
if (hr != S_OK)
1822+
goto shortcut_errorw;
1823+
# endif
1824+
1825+
// Get the path to the link target.
1826+
ZeroMemory(wsz, MAX_PATH * sizeof(WCHAR));
1827+
hr = pslw->lpVtbl->GetPath(pslw, wsz, MAX_PATH, &ffdw, 0);
1828+
if (hr == S_OK && wsz[0] != NUL)
1829+
rfname = utf16_to_enc(wsz, NULL);
1830+
1831+
shortcut_errorw:
1832+
vim_free(p);
1833+
if (hr == S_OK)
1834+
goto shortcut_end;
1835+
}
1836+
}
1837+
/* Retry with non-wide function (for Windows 98). */
1838+
}
1839+
# endif
17781840
// create a link manager object and request its interface
17791841
hr = CoCreateInstance(
17801842
&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
17811843
&IID_IShellLink, (void**)&psl);
17821844
if (hr != S_OK)
1783-
goto shortcut_error;
1845+
goto shortcut_end;
17841846

17851847
// Get a pointer to the IPersistFile interface.
17861848
hr = psl->lpVtbl->QueryInterface(
17871849
psl, &IID_IPersistFile, (void**)&ppf);
17881850
if (hr != S_OK)
1789-
goto shortcut_error;
1851+
goto shortcut_end;
17901852

17911853
// full path string must be in Unicode.
17921854
MultiByteToWideChar(CP_ACP, 0, fname, -1, wsz, MAX_PATH);
17931855

17941856
// "load" the name and resolve the link
17951857
hr = ppf->lpVtbl->Load(ppf, wsz, STGM_READ);
17961858
if (hr != S_OK)
1797-
goto shortcut_error;
1798-
#if 0 // This makes Vim wait a long time if the target doesn't exist.
1859+
goto shortcut_end;
1860+
# if 0 // This makes Vim wait a long time if the target doesn't exist.
17991861
hr = psl->lpVtbl->Resolve(psl, NULL, SLR_NO_UI);
18001862
if (hr != S_OK)
1801-
goto shortcut_error;
1802-
#endif
1863+
goto shortcut_end;
1864+
# endif
18031865

18041866
// Get the path to the link target.
18051867
ZeroMemory(buf, MAX_PATH);
18061868
hr = psl->lpVtbl->GetPath(psl, buf, MAX_PATH, &ffd, 0);
18071869
if (hr == S_OK && buf[0] != NUL)
18081870
rfname = vim_strsave(buf);
18091871

1810-
shortcut_error:
1872+
shortcut_end:
18111873
// Release all interface pointers (both belong to the same object)
18121874
if (ppf != NULL)
18131875
ppf->lpVtbl->Release(ppf);
18141876
if (psl != NULL)
18151877
psl->lpVtbl->Release(psl);
1878+
# ifdef FEAT_MBYTE
1879+
if (pslw != NULL)
1880+
pslw->lpVtbl->Release(pslw);
1881+
# endif
18161882

18171883
CoUninitialize();
18181884
return rfname;

0 commit comments

Comments
 (0)