Skip to content

Commit 21c825c

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents dc9772e + 7567d0b commit 21c825c

41 files changed

Lines changed: 859 additions & 801 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

runtime/doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ xxd.man: xxd.1
344344
nroff -man xxd.1 | sed -e s/.//g > xxd.man
345345

346346
uganda.nsis.txt: uganda.txt
347-
sed -e 's/[ ]*\*[-a-zA-Z0-9.]*\*//g' -e 's/vim:tw=78://' \
347+
sed -e 's/[ ]*\*[-a-zA-Z0-9.]*\*//g' -e 's/vim:tw=78:.*//' \
348348
uganda.txt | uniq >uganda.nsis.txt
349349

350350
# Awk version of .txt to .html conversion.

runtime/doc/eval.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 8.0. Last change: 2017 Oct 28
1+
*eval.txt* For Vim version 8.0. Last change: 2017 Nov 16
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -8721,7 +8721,7 @@ winwidth({nr}) *winwidth()*
87218721
Examples: >
87228722
:echo "The current window has " . winwidth(0) . " columns."
87238723
:if winwidth(0) <= 50
8724-
: exe "normal 50\<C-W>|"
8724+
: 50 wincmd |
87258725
:endif
87268726
< For getting the terminal or screen size, see the 'columns'
87278727
option.
@@ -8762,8 +8762,17 @@ writefile({list}, {fname} [, {flags}])
87628762
appended to the file: >
87638763
:call writefile(["foo"], "event.log", "a")
87648764
:call writefile(["bar"], "event.log", "a")
8765-
8766-
< All NL characters are replaced with a NUL character.
8765+
<
8766+
When {flags} contains "s" then fsync() is called after writing
8767+
the file. This flushes the file to disk, if possible. This
8768+
takes more time but avoids losing the file if the system
8769+
crashes.
8770+
When {flags} does not contain "S" or "s" then fsync is called
8771+
if the 'fsync' option is set.
8772+
When {flags} contains "S" then fsync() is not called, even
8773+
when 'fsync' is set.
8774+
8775+
All NL characters are replaced with a NUL character.
87678776
Inserting CR characters needs to be done before passing {list}
87688777
to writefile().
87698778
An existing file is overwritten, if possible.

src/Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,18 +2114,14 @@ run_message_test: $(MESSAGE_TEST_TARGET)
21142114
# Run individual OLD style test.
21152115
# These do not depend on the executable, compile it when needed.
21162116
test1 \
2117-
test_close_count \
2118-
test_erasebackword \
21192117
test_eval \
2120-
test_fixeol \
2121-
test_listchars \
21222118
test_wordcount \
21232119
test3 test11 test14 test15 test17 \
21242120
test29 test30 test36 test37 test39 \
21252121
test42 test44 test48 test49 \
21262122
test50 test52 test59 \
2127-
test64 test68 test69 \
2128-
test70 test72 test73 \
2123+
test64 test69 \
2124+
test70 test72 \
21292125
test85 test86 test87 test88 \
21302126
test94 test95 test99 test108:
21312127
cd testdir; rm -f [email protected]; $(MAKE) -f Makefile [email protected] VIMPROG=../$(VIMTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE)
@@ -2150,6 +2146,7 @@ test_arglist \
21502146
test_charsearch_utf8 \
21512147
test_cindent \
21522148
test_clientserver \
2149+
test_close_count \
21532150
test_cmdline \
21542151
test_command_count \
21552152
test_comparators \
@@ -2162,6 +2159,7 @@ test_arglist \
21622159
test_digraph \
21632160
test_display \
21642161
test_edit \
2162+
test_erasebackword \
21652163
test_escaped_glob \
21662164
test_ex_undo \
21672165
test_ex_z \
@@ -2181,7 +2179,9 @@ test_arglist \
21812179
test_filetype \
21822180
test_filter_cmd \
21832181
test_filter_map \
2182+
test_find_complete \
21842183
test_findfile \
2184+
test_fixeol \
21852185
test_float_func \
21862186
test_fnameescape \
21872187
test_fnamemodify \
@@ -2217,6 +2217,7 @@ test_arglist \
22172217
test_let \
22182218
test_lineending \
22192219
test_lispwords \
2220+
test_listchars \
22202221
test_listdict \
22212222
test_listlbr \
22222223
test_listlbr_utf8 \
@@ -2289,6 +2290,7 @@ test_arglist \
22892290
test_tcl \
22902291
test_terminal \
22912292
test_terminal_fail \
2293+
test_textformat \
22922294
test_textobjects \
22932295
test_timers \
22942296
test_true_false \

src/auto/configure

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12201,13 +12201,13 @@ if test "x$vim_cv_getcwd_broken" = "xyes" ; then
1220112201

1220212202
fi
1220312203

12204-
for ac_func in fchdir fchown fsync getcwd getpseudotty \
12204+
for ac_func in fchdir fchown fchmod fsync getcwd getpseudotty \
1220512205
getpwent getpwnam getpwuid getrlimit gettimeofday getwd lstat \
1220612206
memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
1220712207
getpgid setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
1220812208
sigprocmask sigvec strcasecmp strerror strftime stricmp strncasecmp \
1220912209
strnicmp strpbrk strtol tgetent towlower towupper iswupper \
12210-
usleep utime utimes mblen
12210+
usleep utime utimes mblen ftruncate
1221112211
do :
1221212212
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1221312213
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

src/config.h.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@
156156
/* Define if you the function: */
157157
#undef HAVE_FCHDIR
158158
#undef HAVE_FCHOWN
159+
#undef HAVE_FCHMOD
160+
#undef HAVE_FLOAT_FUNCS
159161
#undef HAVE_FSEEKO
160162
#undef HAVE_FSYNC
161-
#undef HAVE_FLOAT_FUNCS
163+
#undef HAVE_FTRUNCATE
162164
#undef HAVE_GETCWD
163165
#undef HAVE_GETPGID
164166
#undef HAVE_GETPSEUDOTTY

src/configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,13 +3740,13 @@ fi
37403740

37413741
dnl Check for functions in one big call, to reduce the size of configure.
37423742
dnl Can only be used for functions that do not require any include.
3743-
AC_CHECK_FUNCS(fchdir fchown fsync getcwd getpseudotty \
3743+
AC_CHECK_FUNCS(fchdir fchown fchmod fsync getcwd getpseudotty \
37443744
getpwent getpwnam getpwuid getrlimit gettimeofday getwd lstat \
37453745
memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
37463746
getpgid setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
37473747
sigprocmask sigvec strcasecmp strerror strftime stricmp strncasecmp \
37483748
strnicmp strpbrk strtol tgetent towlower towupper iswupper \
3749-
usleep utime utimes mblen)
3749+
usleep utime utimes mblen ftruncate)
37503750
AC_FUNC_FSEEKO
37513751

37523752
dnl define _LARGE_FILES, _FILE_OFFSET_BITS and _LARGEFILE_SOURCE when

src/evalfunc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13375,6 +13375,9 @@ f_writefile(typval_T *argvars, typval_T *rettv)
1337513375
{
1337613376
int binary = FALSE;
1337713377
int append = FALSE;
13378+
#ifdef HAVE_FSYNC
13379+
int do_fsync = p_fs;
13380+
#endif
1337813381
char_u *fname;
1337913382
FILE *fd;
1338013383
int ret = 0;
@@ -13407,6 +13410,12 @@ f_writefile(typval_T *argvars, typval_T *rettv)
1340713410
binary = TRUE;
1340813411
if (vim_strchr(arg2, 'a') != NULL)
1340913412
append = TRUE;
13413+
#ifdef HAVE_FSYNC
13414+
if (vim_strchr(arg2, 's') != NULL)
13415+
do_fsync = TRUE;
13416+
else if (vim_strchr(arg2, 'S') != NULL)
13417+
do_fsync = FALSE;
13418+
#endif
1341013419
}
1341113420

1341213421
fname = get_tv_string_chk(&argvars[1]);
@@ -13425,6 +13434,10 @@ f_writefile(typval_T *argvars, typval_T *rettv)
1342513434
{
1342613435
if (write_list(fd, list, binary) == FAIL)
1342713436
ret = -1;
13437+
#ifdef HAVE_FSYNC
13438+
else if (do_fsync && fsync(fileno(fd)) != 0)
13439+
EMSG(_(e_fsync));
13440+
#endif
1342813441
fclose(fd);
1342913442
}
1343013443

src/ex_getln.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ getcmdline(
220220
pos_T match_end;
221221
# ifdef FEAT_DIFF
222222
int old_topfill;
223-
int init_topfill = curwin->w_topfill;
223+
int init_topfill = curwin->w_topfill;
224224
# endif
225225
linenr_T old_botline;
226226
linenr_T init_botline = curwin->w_botline;
@@ -1723,11 +1723,17 @@ getcmdline(
17231723
if (p_is && !cmd_silent && (firstc == '/' || firstc == '?'))
17241724
{
17251725
pos_T t;
1726+
char_u *pat;
17261727
int search_flags = SEARCH_NOOF;
17271728

17281729
if (ccline.cmdlen == 0)
17291730
goto cmdline_not_changed;
17301731

1732+
if (firstc == ccline.cmdbuff[0])
1733+
pat = last_search_pattern();
1734+
else
1735+
pat = ccline.cmdbuff;
1736+
17311737
save_last_search_pattern();
17321738
cursor_off();
17331739
out_flush();
@@ -1747,7 +1753,7 @@ getcmdline(
17471753
++emsg_off;
17481754
i = searchit(curwin, curbuf, &t,
17491755
c == Ctrl_G ? FORWARD : BACKWARD,
1750-
ccline.cmdbuff, count, search_flags,
1756+
pat, count, search_flags,
17511757
RE_SEARCH, 0, NULL, NULL);
17521758
--emsg_off;
17531759
if (i)

src/fileio.c

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,6 +3863,7 @@ buf_write(
38633863
char_u *rootname;
38643864
#if defined(UNIX)
38653865
int did_set_shortname;
3866+
mode_t umask_save;
38663867
#endif
38673868

38683869
copybuf = alloc(BUFSIZE + 1);
@@ -3994,22 +3995,30 @@ buf_write(
39943995
/* remove old backup, if present */
39953996
mch_remove(backup);
39963997
/* Open with O_EXCL to avoid the file being created while
3997-
* we were sleeping (symlink hacker attack?) */
3998+
* we were sleeping (symlink hacker attack?). Reset umask
3999+
* if possible to avoid mch_setperm() below. */
4000+
#ifdef UNIX
4001+
umask_save = umask(0);
4002+
#endif
39984003
bfd = mch_open((char *)backup,
39994004
O_WRONLY|O_CREAT|O_EXTRA|O_EXCL|O_NOFOLLOW,
40004005
perm & 0777);
4006+
#ifdef UNIX
4007+
(void)umask(umask_save);
4008+
#endif
40014009
if (bfd < 0)
40024010
{
40034011
vim_free(backup);
40044012
backup = NULL;
40054013
}
40064014
else
40074015
{
4008-
/* set file protection same as original file, but
4009-
* strip s-bit */
4016+
/* Set file protection same as original file, but
4017+
* strip s-bit. Only needed if umask() wasn't used
4018+
* above. */
4019+
#ifndef UNIX
40104020
(void)mch_setperm(backup, perm & 0777);
4011-
4012-
#ifdef UNIX
4021+
#else
40134022
/*
40144023
* Try to set the group of the backup same as the
40154024
* original file. If this fails, set the protection
@@ -4377,6 +4386,11 @@ buf_write(
43774386
}
43784387
else
43794388
{
4389+
#ifdef HAVE_FTRUNCATE
4390+
# define TRUNC_ON_OPEN 0
4391+
#else
4392+
# define TRUNC_ON_OPEN O_TRUNC
4393+
#endif
43804394
/*
43814395
* Open the file "wfname" for writing.
43824396
* We may try to open the file twice: If we can't write to the file
@@ -4389,7 +4403,7 @@ buf_write(
43894403
*/
43904404
while ((fd = mch_open((char *)wfname, O_WRONLY | O_EXTRA | (append
43914405
? (forceit ? (O_APPEND | O_CREAT) : O_APPEND)
4392-
: (O_CREAT | O_TRUNC))
4406+
: (O_CREAT | TRUNC_ON_OPEN))
43934407
, perm < 0 ? 0666 : (perm & 0777))) < 0)
43944408
{
43954409
/*
@@ -4482,6 +4496,30 @@ buf_write(
44824496
}
44834497
write_info.bw_fd = fd;
44844498

4499+
#if defined(UNIX)
4500+
{
4501+
stat_T st;
4502+
4503+
/* Double check we are writing the intended file before making
4504+
* any changes. */
4505+
if (overwriting
4506+
&& (!dobackup || backup_copy)
4507+
&& fname == wfname
4508+
&& perm >= 0
4509+
&& mch_fstat(fd, &st) == 0
4510+
&& st.st_ino != st_old.st_ino)
4511+
{
4512+
close(fd);
4513+
errmsg = (char_u *)_("E949: File changed while writing");
4514+
goto fail;
4515+
}
4516+
}
4517+
#endif
4518+
#ifdef HAVE_FTRUNCATE
4519+
if (!append)
4520+
ftruncate(fd, (off_t)0);
4521+
#endif
4522+
44854523
#if defined(WIN3264)
44864524
if (backup != NULL && overwriting && !append)
44874525
{
@@ -4733,7 +4771,7 @@ buf_write(
47334771
*/
47344772
if (p_fs && fsync(fd) != 0 && !device)
47354773
{
4736-
errmsg = (char_u *)_("E667: Fsync failed");
4774+
errmsg = (char_u *)_(e_fsync);
47374775
end = 0;
47384776
}
47394777
#endif
@@ -4752,15 +4790,17 @@ buf_write(
47524790
# ifdef HAVE_FCHOWN
47534791
stat_T st;
47544792

4755-
/* don't change the owner when it's already OK, some systems remove
4756-
* permission or ACL stuff */
4793+
/* Don't change the owner when it's already OK, some systems remove
4794+
* permission or ACL stuff. */
47574795
if (mch_stat((char *)wfname, &st) < 0
47584796
|| st.st_uid != st_old.st_uid
47594797
|| st.st_gid != st_old.st_gid)
47604798
{
4761-
ignored = fchown(fd, st_old.st_uid, st_old.st_gid);
4762-
if (perm >= 0) /* set permission again, may have changed */
4763-
(void)mch_setperm(wfname, perm);
4799+
/* changing owner might not be possible */
4800+
ignored = fchown(fd, st_old.st_uid, -1);
4801+
/* if changing group fails clear the group permissions */
4802+
if (fchown(fd, -1, st_old.st_gid) == -1 && perm > 0)
4803+
perm &= ~070;
47644804
}
47654805
# endif
47664806
buf_setino(buf);
@@ -4770,18 +4810,26 @@ buf_write(
47704810
buf_setino(buf);
47714811
#endif
47724812

4813+
#ifdef UNIX
4814+
if (made_writable)
4815+
perm &= ~0200; /* reset 'w' bit for security reasons */
4816+
#endif
4817+
#ifdef HAVE_FCHMOD
4818+
/* set permission of new file same as old file */
4819+
if (perm >= 0)
4820+
(void)mch_fsetperm(fd, perm);
4821+
#endif
47734822
if (close(fd) != 0)
47744823
{
47754824
errmsg = (char_u *)_("E512: Close failed");
47764825
end = 0;
47774826
}
47784827

4779-
#ifdef UNIX
4780-
if (made_writable)
4781-
perm &= ~0200; /* reset 'w' bit for security reasons */
4782-
#endif
4783-
if (perm >= 0) /* set perm. of new file same as old file */
4828+
#ifndef HAVE_FCHMOD
4829+
/* set permission of new file same as old file */
4830+
if (perm >= 0)
47844831
(void)mch_setperm(wfname, perm);
4832+
#endif
47854833
#ifdef HAVE_ACL
47864834
/*
47874835
* Probably need to set the ACL before changing the user (can't set the

src/globals.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,9 @@ EXTERN char_u e_isadir2[] INIT(= N_("E17: \"%s\" is a directory"));
14541454
#ifdef FEAT_LIBCALL
14551455
EXTERN char_u e_libcall[] INIT(= N_("E364: Library call failed for \"%s()\""));
14561456
#endif
1457+
#ifdef HAVE_FSYNC
1458+
EXTERN char_u e_fsync[] INIT(= N_("E667: Fsync failed"));
1459+
#endif
14571460
#if defined(DYNAMIC_PERL) \
14581461
|| defined(DYNAMIC_PYTHON) || defined(DYNAMIC_PYTHON3) \
14591462
|| defined(DYNAMIC_RUBY) \

0 commit comments

Comments
 (0)