Skip to content

Commit

Permalink
win32: Use _commit() instead of dup() and close()
Browse files Browse the repository at this point in the history
Currently we use `dup()` and `close()` to flush a file to disk. However,
MSVC and other win32 compilers have `_commit()` for that purpose.
We can simply use it.
  • Loading branch information
k-takata committed Sep 21, 2018
1 parent 3f3fb0b commit 049b75f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
13 changes: 3 additions & 10 deletions src/memfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,6 @@ mf_sync(memfile_T *mfp, int flags)
{
int status;
bhdr_T *hp;
#if defined(SYNC_DUP_CLOSE)
int fd;
#endif
int got_int_save = got_int;

if (mfp->mf_fd < 0) /* there is no file, nothing to do */
Expand Down Expand Up @@ -624,13 +621,9 @@ mf_sync(memfile_T *mfp, int flags)
status = FAIL;
}
#endif
#ifdef SYNC_DUP_CLOSE
/*
* Win32 is a bit more work: Duplicate the file handle and close it.
* This should flush the file to disk.
*/
if ((fd = dup(mfp->mf_fd)) >= 0)
close(fd);
#ifdef WIN32
if (_commit(mfp->mf_fd))
status = FAIL;
#endif
#ifdef AMIGA
# if defined(__AROS__) || defined(__amigaos4__)
Expand Down
1 change: 0 additions & 1 deletion src/os_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
#define HAVE_AVAIL_MEM

#ifndef HAVE_CONFIG_H
/* #define SYNC_DUP_CLOSE sync() a file with dup() and close() */
# define HAVE_STRING_H
# define HAVE_STRCSPN
# define HAVE_MEMSET
Expand Down
1 change: 0 additions & 1 deletion src/os_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#define BINARY_FILE_IO
#define USE_EXE_NAME /* use argv[0] for $VIM */
#define SYNC_DUP_CLOSE /* sync() a file with dup() and close() */
#define USE_TERM_CONSOLE
#ifndef HAVE_STRING_H
# define HAVE_STRING_H
Expand Down

0 comments on commit 049b75f

Please sign in to comment.