diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-03-31 11:37:57 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-03-31 11:37:57 +0100 |
commit | 4dea2d92e4c308b064ed1dd7b2ba7527a0d6b0a0 (patch) | |
tree | a7be19a7aa8b4a9c4e48084639ad51db96f36db6 /src/filepath.c | |
parent | d1d2684c8006105444d249e846576c23d79ad4ee (diff) |
patch 8.2.4653: "import autoload" does not check the file namev8.2.4653
Problem: "import autoload" does not check the file name.
Solution: Give an error if the file is not readable. (closes #10049)
Diffstat (limited to 'src/filepath.c')
-rw-r--r-- | src/filepath.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/filepath.c b/src/filepath.c index f0da60f452..851091e57a 100644 --- a/src/filepath.c +++ b/src/filepath.c @@ -893,32 +893,34 @@ f_exepath(typval_T *argvars, typval_T *rettv) } /* - * "filereadable()" function + * Return TRUE if "fname" is a readable file. */ - void -f_filereadable(typval_T *argvars, typval_T *rettv) + int +file_is_readable(char_u *fname) { int fd; - char_u *p; - int n; - - if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) - return; #ifndef O_NONBLOCK # define O_NONBLOCK 0 #endif - p = tv_get_string(&argvars[0]); - if (*p && !mch_isdir(p) && (fd = mch_open((char *)p, - O_RDONLY | O_NONBLOCK, 0)) >= 0) + if (*fname && !mch_isdir(fname) + && (fd = mch_open((char *)fname, O_RDONLY | O_NONBLOCK, 0)) >= 0) { - n = TRUE; close(fd); + return TRUE; } - else - n = FALSE; + return FALSE; +} - rettv->vval.v_number = n; +/* + * "filereadable()" function + */ + void +f_filereadable(typval_T *argvars, typval_T *rettv) +{ + if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) + return; + rettv->vval.v_number = file_is_readable(tv_get_string(&argvars[0])); } /* @@ -1761,7 +1763,7 @@ read_file_or_blob(typval_T *argvars, typval_T *rettv, int always_blob) if (mch_isdir(fname)) { - semsg(_(e_src_is_directory), fname); + semsg(_(e_str_is_directory), fname); return; } if (*fname == NUL || (fd = mch_fopen((char *)fname, READBIN)) == NULL) |