diff options
author | Stefan Hoffmann <stefan991@gmail.com> | 2014-03-16 16:06:55 +0100 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-03 10:30:03 -0300 |
commit | f762a9e195cdd1db3d57561a5e82a1ea6799d8ba (patch) | |
tree | f34516c296e1aadb06e7fcda3096f107dc1df45a /src | |
parent | 071d28076f4ee057764359999cf2fabc75e99314 (diff) | |
download | rneovim-f762a9e195cdd1db3d57561a5e82a1ea6799d8ba.tar.gz rneovim-f762a9e195cdd1db3d57561a5e82a1ea6799d8ba.tar.bz2 rneovim-f762a9e195cdd1db3d57561a5e82a1ea6799d8ba.zip |
move filewritable() into /src/os/fs.c and rename it
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 3 | ||||
-rw-r--r-- | src/misc2.c | 27 | ||||
-rw-r--r-- | src/misc2.h | 1 | ||||
-rw-r--r-- | src/os/fs.c | 13 | ||||
-rw-r--r-- | src/os/os.h | 1 | ||||
-rw-r--r-- | src/spell.c | 4 |
6 files changed, 18 insertions, 31 deletions
diff --git a/src/eval.c b/src/eval.c index e29853a1b5..787ef7b30a 100644 --- a/src/eval.c +++ b/src/eval.c @@ -8877,7 +8877,8 @@ static void f_filereadable(typval_T *argvars, typval_T *rettv) */ static void f_filewritable(typval_T *argvars, typval_T *rettv) { - rettv->vval.v_number = filewritable(get_tv_string(&argvars[0])); + char *filename = (char *)get_tv_string(&argvars[0]); + rettv->vval.v_number = os_file_is_writable(filename); } static void findfilendir(typval_T *argvars, typval_T *rettv, diff --git a/src/misc2.c b/src/misc2.c index cefcc568cc..180ebedcd8 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -1667,33 +1667,6 @@ void sort_strings(char_u **files, int count) } /* - * Return 0 for not writable, 1 for writable file, 2 for a dir which we have - * rights to write into. - */ -int filewritable(char_u *fname) -{ - int retval = 0; -#if defined(UNIX) || defined(VMS) - int perm = 0; -#endif - -#if defined(UNIX) || defined(VMS) - perm = os_getperm(fname); -#endif - if ( -# if defined(UNIX) || defined(VMS) - (perm & 0222) && -# endif - mch_access((char *)fname, W_OK) == 0 - ) { - ++retval; - if (os_isdir(fname)) - ++retval; - } - return retval; -} - -/* * Print an error message with one or two "%s" and one or two string arguments. * This is not in message.c to avoid a warning for prototypes. */ diff --git a/src/misc2.h b/src/misc2.h index 66971c4d4f..41a87ab372 100644 --- a/src/misc2.h +++ b/src/misc2.h @@ -72,7 +72,6 @@ int vim_chdirfile(char_u *fname); int illegal_slash(char *name); int vim_chdir(char_u *new_dir); void sort_strings(char_u **files, int count); -int filewritable(char_u *fname); int emsg3(char_u *s, char_u *a1, char_u *a2); int emsgn(char_u *s, long n); int get2c(FILE *fd); diff --git a/src/os/fs.c b/src/os/fs.c index 71dee4dd3d..db366769b2 100644 --- a/src/os/fs.c +++ b/src/os/fs.c @@ -288,3 +288,16 @@ int os_file_is_readonly(const char *name) } } +// return 0 for not writable, 1 for writable file, 2 for a dir which we have +// rights to write into. +int os_file_is_writable(const char *name) +{ + if (mch_access(name, W_OK) == 0) { + if (os_isdir((char_u *)name)) { + return 2; + } + return 1; + } + return 0; +} + diff --git a/src/os/os.h b/src/os/os.h index e4f5af5057..8999d1480b 100644 --- a/src/os/os.h +++ b/src/os/os.h @@ -69,5 +69,6 @@ int os_get_user_name(char *s, size_t len); int os_get_uname(uid_t uid, char *s, size_t len); char *os_get_user_directory(const char *name); int os_file_is_readonly(const char *name); +int os_file_is_writable(const char *name); #endif // NEOVIM_OS_OS_H diff --git a/src/spell.c b/src/spell.c index 7a986d98d2..52a85171eb 100644 --- a/src/spell.c +++ b/src/spell.c @@ -8585,7 +8585,7 @@ static void init_spellfile(void) else /* Copy the path from 'runtimepath' to buf[]. */ copy_option_part(&rtp, buf, MAXPATHL, ","); - if (filewritable(buf) == 2) { + if (os_file_is_writable((char *)buf) == 2) { /* Use the first language name from 'spelllang' and the * encoding used in the first loaded .spl file. */ if (aspath) @@ -8595,7 +8595,7 @@ static void init_spellfile(void) /* Create the "spell" directory if it doesn't exist yet. */ l = (int)STRLEN(buf); vim_snprintf((char *)buf + l, MAXPATHL - l, "/spell"); - if (filewritable(buf) != 2) + if (os_file_is_writable((char *)buf) != 2) vim_mkdir(buf, 0755); l = (int)STRLEN(buf); |