diff options
author | Stefan Hoffmann <stefan991@gmail.com> | 2014-05-02 20:08:36 +0200 |
---|---|---|
committer | Stefan Hoffmann <stefan991@gmail.com> | 2014-05-09 15:49:33 +0200 |
commit | 8e8dae71da51f068243ecda05bc250d59918f15b (patch) | |
tree | 18c3c1052dcb1cfc32d32ef232e76b30db9b2369 | |
parent | 902ad8d94d9a1eafde858793587037e620c6ee6f (diff) | |
download | rneovim-8e8dae71da51f068243ecda05bc250d59918f15b.tar.gz rneovim-8e8dae71da51f068243ecda05bc250d59918f15b.tar.bz2 rneovim-8e8dae71da51f068243ecda05bc250d59918f15b.zip |
replaced some mch_lstat()
-rw-r--r-- | src/eval.c | 21 | ||||
-rw-r--r-- | src/memfile.c | 13 | ||||
-rw-r--r-- | src/path.c | 30 | ||||
-rw-r--r-- | src/quickfix.c | 14 |
4 files changed, 32 insertions, 46 deletions
diff --git a/src/eval.c b/src/eval.c index 80135305c6..9300b9a77b 100644 --- a/src/eval.c +++ b/src/eval.c @@ -9729,44 +9729,45 @@ static void f_getftime(typval_T *argvars, typval_T *rettv) static void f_getftype(typval_T *argvars, typval_T *rettv) { char_u *fname; - struct stat st; char_u *type = NULL; char *t; fname = get_tv_string(&argvars[0]); rettv->v_type = VAR_STRING; - if (mch_lstat((char *)fname, &st) >= 0) { + FileInfo file_info; + if (os_get_file_info_link((char *)fname, &file_info)) { + uint64_t mode = file_info.stat.st_mode; #ifdef S_ISREG - if (S_ISREG(st.st_mode)) + if (S_ISREG(mode)) t = "file"; - else if (S_ISDIR(st.st_mode)) + else if (S_ISDIR(mode)) t = "dir"; # ifdef S_ISLNK - else if (S_ISLNK(st.st_mode)) + else if (S_ISLNK(mode)) t = "link"; # endif # ifdef S_ISBLK - else if (S_ISBLK(st.st_mode)) + else if (S_ISBLK(mode)) t = "bdev"; # endif # ifdef S_ISCHR - else if (S_ISCHR(st.st_mode)) + else if (S_ISCHR(mode)) t = "cdev"; # endif # ifdef S_ISFIFO - else if (S_ISFIFO(st.st_mode)) + else if (S_ISFIFO(mode)) t = "fifo"; # endif # ifdef S_ISSOCK - else if (S_ISSOCK(st.st_mode)) + else if (S_ISSOCK(mode)) t = "fifo"; # endif else t = "other"; #else # ifdef S_IFMT - switch (st.st_mode & S_IFMT) { + switch (mode & S_IFMT) { case S_IFREG: t = "file"; break; case S_IFDIR: t = "dir"; break; # ifdef S_IFLNK diff --git a/src/memfile.c b/src/memfile.c index 87ac56b955..9431101d8d 100644 --- a/src/memfile.c +++ b/src/memfile.c @@ -1041,10 +1041,6 @@ mf_do_open ( int flags /* flags for open() */ ) { -#ifdef HAVE_LSTAT - struct stat sb; -#endif - mfp->mf_fname = fname; /* @@ -1054,17 +1050,16 @@ mf_do_open ( */ mf_set_ffname(mfp); -#ifdef HAVE_LSTAT /* * Extra security check: When creating a swap file it really shouldn't * exist yet. If there is a symbolic link, this is most likely an attack. */ - if ((flags & O_CREAT) && mch_lstat((char *)mfp->mf_fname, &sb) >= 0) { + FileInfo file_info; + if ((flags & O_CREAT) + && os_get_file_info_link((char *)mfp->mf_fname, &file_info)) { mfp->mf_fd = -1; EMSG(_("E300: Swap file already exists (symlink attack?)")); - } else -#endif - { + } else { /* * try to open the file */ diff --git a/src/path.c b/src/path.c index 93366c93ab..541e1e1724 100644 --- a/src/path.c +++ b/src/path.c @@ -1285,7 +1285,6 @@ void simplify_filename(char_u *filename) if (components > 0) { /* strip one preceding component */ int do_strip = FALSE; char_u saved_char; - struct stat st; /* Don't strip for an erroneous file name. */ if (!stripping_disabled) { @@ -1294,12 +1293,10 @@ void simplify_filename(char_u *filename) * link that refers to a non-existent file. */ saved_char = p[-1]; p[-1] = NUL; -#ifdef UNIX - if (mch_lstat((char *)filename, &st) < 0) -#else - if (mch_stat((char *)filename, &st) < 0) -#endif + FileInfo file_info; + if (!os_get_file_info_link((char *)filename, &file_info)) { do_strip = TRUE; + } p[-1] = saved_char; --p; @@ -1320,40 +1317,37 @@ void simplify_filename(char_u *filename) * components. */ saved_char = *tail; *tail = NUL; - if (mch_stat((char *)filename, &st) >= 0) + if (os_get_file_info((char *)filename, &file_info)) { do_strip = TRUE; + } else stripping_disabled = TRUE; *tail = saved_char; -#ifdef UNIX if (do_strip) { - struct stat new_st; - - /* On Unix, the check for the unstripped file name + /* The check for the unstripped file name * above works also for a symbolic link pointing to * a searchable directory. But then the parent of * the directory pointed to by the link must be the * same as the stripped file name. (The latter * exists in the file system since it is the * component's parent directory.) */ - if (p == start && relative) - (void)mch_stat(".", &new_st); - else { + FileInfo new_file_info; + if (p == start && relative) { + os_get_file_info(".", &new_file_info); + } else { saved_char = *p; *p = NUL; - (void)mch_stat((char *)filename, &new_st); + os_get_file_info((char *)filename, &new_file_info); *p = saved_char; } - if (new_st.st_ino != st.st_ino || - new_st.st_dev != st.st_dev) { + if (!os_file_info_id_equal(&file_info, &new_file_info)) { do_strip = FALSE; /* We don't disable stripping of later * components since the unstripped path name is * still valid. */ } } -#endif } } diff --git a/src/quickfix.c b/src/quickfix.c index 91ebe9795b..94b2b05501 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -2573,9 +2573,6 @@ static char_u *get_mef_name(void) char_u *name; static int start = -1; static int off = 0; -#ifdef HAVE_LSTAT - struct stat sb; -#endif if (*p_mef == NUL) { name = vim_tempname('e'); @@ -2602,13 +2599,12 @@ static char_u *get_mef_name(void) STRCPY(name, p_mef); sprintf((char *)name + (p - p_mef), "%d%d", start, off); STRCAT(name, p + 2); - if (!os_file_exists(name) -#ifdef HAVE_LSTAT - /* Don't accept a symbolic link, its a security risk. */ - && mch_lstat((char *)name, &sb) < 0 -#endif - ) + // Don't accept a symbolic link, its a security risk. + FileInfo file_info; + bool file_or_link_found = os_get_file_info_link((char *)name, &file_info); + if (!file_or_link_found) { break; + } free(name); } return name; |