summaryrefslogtreecommitdiffstats
path: root/src/filepath.c
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2024-06-03 22:59:27 +0200
committerChristian Brabandt <cb@256bit.org>2024-06-03 23:01:40 +0200
commit60c8743ab6c90e402e6ed49d27455ef7e5698abe (patch)
tree441cc398a542d10a60cd9c1dd7862ebcf0f1353e /src/filepath.c
parent0a0830624a260660c7fa692ecb7e6e5de09114ba (diff)
patch 9.1.0465: missing filecopy() functionv9.1.0465
Problem: missing filecopy() function Solution: implement filecopy() Vim script function (Shougo Matsushita) closes: #12346 Co-authored-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/filepath.c')
-rw-r--r--src/filepath.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/filepath.c b/src/filepath.c
index e68075a45e..9f68d7c688 100644
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -2649,6 +2649,31 @@ f_browsedir(typval_T *argvars UNUSED, typval_T *rettv)
rettv->v_type = VAR_STRING;
}
+/*
+ * "filecopy()" function
+ */
+ void
+f_filecopy(typval_T *argvars, typval_T *rettv)
+{
+ char_u *from;
+ stat_T st;
+
+ rettv->vval.v_number = FALSE;
+
+ if (check_restricted() || check_secure()
+ || check_for_string_arg(argvars, 0) == FAIL
+ || check_for_string_arg(argvars, 1) == FAIL)
+ return;
+
+ from = tv_get_string(&argvars[0]);
+
+ if (mch_lstat((char *)from, &st) >= 0
+ && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
+ rettv->vval.v_number = vim_copyfile(
+ tv_get_string(&argvars[0]),
+ tv_get_string(&argvars[1])) == OK ? TRUE : FALSE;
+}
+
#endif // FEAT_EVAL
/*