diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-06-30 16:00:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-30 16:00:35 +0200 |
commit | 3b504e7c8d20bb41ef6b6f95e46527766438046a (patch) | |
tree | 82e5b687f5cd523977bb5dac3690ad4deba77f2d /src | |
parent | fdd8dcae01beb66397226ad65e4f1bbd3d1dd55c (diff) | |
download | rneovim-3b504e7c8d20bb41ef6b6f95e46527766438046a.tar.gz rneovim-3b504e7c8d20bb41ef6b6f95e46527766438046a.tar.bz2 rneovim-3b504e7c8d20bb41ef6b6f95e46527766438046a.zip |
fileio.c: eliminate set_file_time() #10357
Introduce os_file_settime(), remove cruft.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/fileio.c | 48 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 16 |
2 files changed, 22 insertions, 42 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index f2a664288b..645812eb75 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -58,10 +58,6 @@ #include "nvim/os/time.h" #include "nvim/os/input.h" -#if defined(HAVE_UTIME) && defined(HAVE_UTIME_H) -# include <utime.h> /* for struct utimbuf */ -#endif - #define BUFSIZE 8192 /* size of normal write buffer */ #define SMBUFSIZE 256 /* size of emergency write buffer */ @@ -190,10 +186,6 @@ struct bw_info { # include "fileio.c.generated.h" #endif -#ifdef UNIX -#endif - - static char *e_auchangedbuf = N_( "E812: Autocommands changed buffer or buffer name"); @@ -2198,34 +2190,6 @@ static void check_marks_read(void) curbuf->b_marks_read = true; } -#ifdef UNIX -static void -set_file_time ( - char_u *fname, - time_t atime, /* access time */ - time_t mtime /* modification time */ -) -{ -# if defined(HAVE_UTIME) && defined(HAVE_UTIME_H) - struct utimbuf buf; - - buf.actime = atime; - buf.modtime = mtime; - (void)utime((char *)fname, &buf); -# else -# if defined(HAVE_UTIMES) - struct timeval tvp[2]; - - tvp[0].tv_sec = atime; - tvp[0].tv_usec = 0; - tvp[1].tv_sec = mtime; - tvp[1].tv_usec = 0; - (void)utimes((char *)fname, (const struct timeval *)&tvp); -# endif -# endif -} -#endif /* UNIX */ - /* * buf_write() - write to file "fname" lines "start" through "end" * @@ -2887,9 +2851,9 @@ buf_write ( } #ifdef UNIX - set_file_time(backup, - file_info_old.stat.st_atim.tv_sec, - file_info_old.stat.st_mtim.tv_sec); + os_file_settime((char *)backup, + file_info_old.stat.st_atim.tv_sec, + file_info_old.stat.st_mtim.tv_sec); #endif #ifdef HAVE_ACL mch_set_acl(backup, acl); @@ -3572,9 +3536,9 @@ restore_backup: vim_rename(backup, (char_u *)org); XFREE_CLEAR(backup); // don't delete the file #ifdef UNIX - set_file_time((char_u *)org, - file_info_old.stat.st_atim.tv_sec, - file_info_old.stat.st_mtim.tv_sec); + os_file_settime(org, + file_info_old.stat.st_atim.tv_sec, + file_info_old.stat.st_mtim.tv_sec); #endif } } diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d5500b230c..1ecca87cde 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -746,6 +746,22 @@ bool os_path_exists(const char_u *path) return os_stat((char *)path, &statbuf) == kLibuvSuccess; } +/// Sets file access and modification times. +/// +/// @see POSIX utime(2) +/// +/// @param path File path. +/// @param atime Last access time. +/// @param mtime Last modification time. +/// +/// @return 0 on success, or negative error code. +int os_file_settime(const char *path, double atime, double mtime) +{ + int r; + RUN_UV_FS_FUNC(r, uv_fs_utime, path, atime, mtime, NULL); + return r; +} + /// Check if a file is readable. /// /// @return true if `name` is readable, otherwise false. |