aboutsummaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-05-09 15:33:00 -0400
committerJustin M. Keyes <justinkz@gmail.com>2014-05-09 15:33:00 -0400
commit1a3ee71de258b416ca6b80f0a9e3b91460df8dc7 (patch)
treea59167e50add55b51ed31c65944cfa78ddd1c290 /src/eval.c
parentf3dda65de157f2d7c35286018c20cbc7597ed748 (diff)
parenteae498c4c5d34c1d0af40ecb430cbbc23b0a8e97 (diff)
downloadrneovim-1a3ee71de258b416ca6b80f0a9e3b91460df8dc7.tar.gz
rneovim-1a3ee71de258b416ca6b80f0a9e3b91460df8dc7.tar.bz2
rneovim-1a3ee71de258b416ca6b80f0a9e3b91460df8dc7.zip
Merge pull request #619 from stefan991/mch_stat-cleanup
Replace `struct stat` with `FileInfo`
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/eval.c b/src/eval.c
index ed246c363b..9300b9a77b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -9664,24 +9664,21 @@ static void f_getfontname(typval_T *argvars, typval_T *rettv)
*/
static void f_getfperm(typval_T *argvars, typval_T *rettv)
{
- char_u *fname;
- struct stat st;
- char_u *perm = NULL;
+ char_u *perm = NULL;
char_u flags[] = "rwx";
- int i;
- fname = get_tv_string(&argvars[0]);
-
- rettv->v_type = VAR_STRING;
- if (mch_stat((char *)fname, &st) >= 0) {
+ char_u *filename = get_tv_string(&argvars[0]);
+ int32_t file_perm = os_getperm(filename);
+ if (file_perm >= 0) {
perm = vim_strsave((char_u *)"---------");
if (perm != NULL) {
- for (i = 0; i < 9; i++) {
- if (st.st_mode & (1 << (8 - i)))
+ for (int i = 0; i < 9; i++) {
+ if (file_perm & (1 << (8 - i)))
perm[i] = flags[i % 3];
}
}
}
+ rettv->v_type = VAR_STRING;
rettv->vval.v_string = perm;
}
@@ -9690,25 +9687,25 @@ static void f_getfperm(typval_T *argvars, typval_T *rettv)
*/
static void f_getfsize(typval_T *argvars, typval_T *rettv)
{
- char_u *fname;
- struct stat st;
-
- fname = get_tv_string(&argvars[0]);
+ char *fname = (char *)get_tv_string(&argvars[0]);
rettv->v_type = VAR_NUMBER;
- if (mch_stat((char *)fname, &st) >= 0) {
- if (os_isdir(fname))
+ off_t file_size;
+ if (os_get_file_size(fname, &file_size)) {
+ if (os_isdir((char_u *)fname))
rettv->vval.v_number = 0;
else {
- rettv->vval.v_number = (varnumber_T)st.st_size;
+ rettv->vval.v_number = (varnumber_T)file_size;
/* non-perfect check for overflow */
- if ((off_t)rettv->vval.v_number != (off_t)st.st_size)
+ if ((off_t)rettv->vval.v_number != file_size) {
rettv->vval.v_number = -2;
+ }
}
- } else
+ } else {
rettv->vval.v_number = -1;
+ }
}
/*
@@ -9716,15 +9713,14 @@ static void f_getfsize(typval_T *argvars, typval_T *rettv)
*/
static void f_getftime(typval_T *argvars, typval_T *rettv)
{
- char_u *fname;
- struct stat st;
+ char *fname = (char *)get_tv_string(&argvars[0]);
- fname = get_tv_string(&argvars[0]);
-
- if (mch_stat((char *)fname, &st) >= 0)
- rettv->vval.v_number = (varnumber_T)st.st_mtime;
- else
+ FileInfo file_info;
+ if (os_get_file_info(fname, &file_info)) {
+ rettv->vval.v_number = (varnumber_T)file_info.stat.st_mtim.tv_sec;
+ } else {
rettv->vval.v_number = -1;
+ }
}
/*
@@ -9733,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