Mercurial > vim
comparison src/evalfunc.c @ 12857:ffdf2e4b5d9a v8.0.1305
patch 8.0.1305: writefile() never calls fsync()
commit https://github.com/vim/vim/commit/7567d0b115e332f61a9f390aaccdf7825b891227
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 16 23:04:15 2017 +0100
patch 8.0.1305: writefile() never calls fsync()
Problem: Writefile() never calls fsync().
Solution: Follow the 'fsync' option with override to enable or disable.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 16 Nov 2017 23:15:05 +0100 |
parents | 963cdeb42c41 |
children | ebb4f6c93598 |
comparison
equal
deleted
inserted
replaced
12856:4c4a02a946f0 | 12857:ffdf2e4b5d9a |
---|---|
13346 static void | 13346 static void |
13347 f_writefile(typval_T *argvars, typval_T *rettv) | 13347 f_writefile(typval_T *argvars, typval_T *rettv) |
13348 { | 13348 { |
13349 int binary = FALSE; | 13349 int binary = FALSE; |
13350 int append = FALSE; | 13350 int append = FALSE; |
13351 #ifdef HAVE_FSYNC | |
13352 int do_fsync = p_fs; | |
13353 #endif | |
13351 char_u *fname; | 13354 char_u *fname; |
13352 FILE *fd; | 13355 FILE *fd; |
13353 int ret = 0; | 13356 int ret = 0; |
13354 listitem_T *li; | 13357 listitem_T *li; |
13355 list_T *list; | 13358 list_T *list; |
13378 return; | 13381 return; |
13379 if (vim_strchr(arg2, 'b') != NULL) | 13382 if (vim_strchr(arg2, 'b') != NULL) |
13380 binary = TRUE; | 13383 binary = TRUE; |
13381 if (vim_strchr(arg2, 'a') != NULL) | 13384 if (vim_strchr(arg2, 'a') != NULL) |
13382 append = TRUE; | 13385 append = TRUE; |
13386 #ifdef HAVE_FSYNC | |
13387 if (vim_strchr(arg2, 's') != NULL) | |
13388 do_fsync = TRUE; | |
13389 else if (vim_strchr(arg2, 'S') != NULL) | |
13390 do_fsync = FALSE; | |
13391 #endif | |
13383 } | 13392 } |
13384 | 13393 |
13385 fname = get_tv_string_chk(&argvars[1]); | 13394 fname = get_tv_string_chk(&argvars[1]); |
13386 if (fname == NULL) | 13395 if (fname == NULL) |
13387 return; | 13396 return; |
13396 } | 13405 } |
13397 else | 13406 else |
13398 { | 13407 { |
13399 if (write_list(fd, list, binary) == FAIL) | 13408 if (write_list(fd, list, binary) == FAIL) |
13400 ret = -1; | 13409 ret = -1; |
13410 #ifdef HAVE_FSYNC | |
13411 else if (do_fsync && fsync(fileno(fd)) != 0) | |
13412 EMSG(_(e_fsync)); | |
13413 #endif | |
13401 fclose(fd); | 13414 fclose(fd); |
13402 } | 13415 } |
13403 | 13416 |
13404 rettv->vval.v_number = ret; | 13417 rettv->vval.v_number = ret; |
13405 } | 13418 } |