diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/diff.c | 7 | ||||
-rw-r--r-- | src/nvim/eval.c | 9 | ||||
-rw-r--r-- | src/nvim/fileio.c | 3 | ||||
-rw-r--r-- | src/nvim/memline.c | 2 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 23 |
5 files changed, 21 insertions, 23 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c index ab0c80112f..e5fa277671 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -947,9 +947,10 @@ void ex_diffpatch(exarg_T *eap) os_remove((char *)buf); // Only continue if the output file was created. - off_t file_size; - bool file_size_success = os_get_file_size((char *)tmp_new, &file_size); - if (!file_size_success || file_size == 0) { + FileInfo file_info; + bool info_ok = os_get_file_info((char *)tmp_new, &file_info); + off_t filesize = os_fileinfo_size(&file_info); + if (!info_ok || filesize == 0) { EMSG(_("E816: Cannot read patch output")); } else { if (curbuf->b_fname != NULL) { diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 34af143446..ff436a5d75 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9165,15 +9165,16 @@ static void f_getfsize(typval_T *argvars, typval_T *rettv) rettv->v_type = VAR_NUMBER; - off_t file_size; - if (os_get_file_size(fname, &file_size)) { + FileInfo file_info; + if (os_get_file_info(fname, &file_info)) { + off_t filesize = os_fileinfo_size(&file_info); if (os_isdir((char_u *)fname)) rettv->vval.v_number = 0; else { - rettv->vval.v_number = (varnumber_T)file_size; + rettv->vval.v_number = (varnumber_T)filesize; /* non-perfect check for overflow */ - if ((off_t)rettv->vval.v_number != file_size) { + if ((off_t)rettv->vval.v_number != filesize) { rettv->vval.v_number = -2; } } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 2e932e9695..245590e7ce 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -5127,9 +5127,10 @@ void buf_reload(buf_T *buf, int orig_mode) } void buf_store_file_info(buf_T *buf, FileInfo *file_info) + FUNC_ATTR_NONNULL_ALL { buf->b_mtime = (long)file_info->stat.st_mtim.tv_sec; - buf->b_orig_size = file_info->stat.st_size; + buf->b_orig_size = os_fileinfo_size(file_info); buf->b_orig_mode = (int)file_info->stat.st_mode; } diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 229de4ae1c..c19d08a396 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1632,7 +1632,7 @@ void ml_sync_all(int check_file, int check_char) FileInfo file_info; if (!os_get_file_info((char *)buf->b_ffname, &file_info) || file_info.stat.st_mtim.tv_sec != buf->b_mtime_read - || (off_t)file_info.stat.st_size != buf->b_orig_size) { + || os_fileinfo_size(&file_info) != buf->b_orig_size) { ml_preserve(buf, FALSE); did_check_timestamps = FALSE; need_check_timestamps = TRUE; /* give message later */ diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index aca7005064..9347afb9bc 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -258,20 +258,6 @@ int os_file_is_writable(const char *name) return 0; } -/// Get the size of a file in bytes. -/// -/// @param[out] size pointer to an off_t to put the size into. -/// @return `true` for success, `false` for failure. -bool os_get_file_size(const char *name, off_t *size) -{ - uv_stat_t statbuf; - if (os_stat(name, &statbuf)) { - *size = statbuf.st_size; - return true; - } - return false; -} - /// Rename a file or directory. /// /// @return `OK` for success, `FAIL` for failure. @@ -408,6 +394,15 @@ uint64_t os_file_info_get_inode(const FileInfo *file_info) return file_info->stat.st_ino; } +/// Get the size of a file from a `FileInfo`. +/// +/// @return filesize in bytes. +off_t os_fileinfo_size(const FileInfo *file_info) + FUNC_ATTR_NONNULL_ALL +{ + return file_info->stat.st_size; +} + /// Get the `FileID` for a given path /// /// @param path Path to the file. |