diff options
author | Thomas Wienecke <wienecke.t@gmail.com> | 2014-03-14 21:54:08 +0100 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-15 11:50:22 -0300 |
commit | c83e8b4dc74ba010e0279b67ef8ffa14103d89f6 (patch) | |
tree | 9969fbde12651043e0986c838c3f21ba924e579d /src | |
parent | 1f578ec5a1baa75b557af2261518d9fb8aee488b (diff) | |
download | rneovim-c83e8b4dc74ba010e0279b67ef8ffa14103d89f6.tar.gz rneovim-c83e8b4dc74ba010e0279b67ef8ffa14103d89f6.tar.bz2 rneovim-c83e8b4dc74ba010e0279b67ef8ffa14103d89f6.zip |
Move and refactor mch_[gs]etperm to os/fs module.
Diffstat (limited to 'src')
-rw-r--r-- | src/os/fs.c | 52 | ||||
-rw-r--r-- | src/os/os.h | 2 | ||||
-rw-r--r-- | src/os_unix.c | 32 | ||||
-rw-r--r-- | src/os_unix.h | 2 | ||||
-rw-r--r-- | src/tag.c | 1 |
5 files changed, 43 insertions, 46 deletions
diff --git a/src/os/fs.c b/src/os/fs.c index e8525cb279..4c1b05b678 100644 --- a/src/os/fs.c +++ b/src/os/fs.c @@ -177,13 +177,8 @@ int mch_is_absolute_path(const char_u *fname) */ int mch_isdir(const char_u *name) { - uv_fs_t request; - int result = uv_fs_stat(uv_default_loop(), &request, (const char*) name, NULL); - uint64_t mode = request.statbuf.st_mode; - - uv_fs_req_cleanup(&request); - - if (0 != result) { + long mode = mch_getperm(name); + if (mode < 0) { return FALSE; } @@ -219,12 +214,9 @@ int mch_can_exe(const char_u *name) */ static int is_executable(const char_u *name) { - uv_fs_t request; - int result = uv_fs_stat(uv_default_loop(), &request, (const char*) name, NULL); - uint64_t mode = request.statbuf.st_mode; - uv_fs_req_cleanup(&request); + long mode = mch_getperm(name); - if (result != 0) { + if (mode < 0) { return FALSE; } @@ -287,3 +279,39 @@ static int is_executable_in_path(const char_u *name) assert(false); return FALSE; } + +/* + * Get file permissions for 'name'. + * Returns -1 when it doesn't exist. + */ +long mch_getperm(const char_u *name) +{ + uv_fs_t request; + int result = uv_fs_stat(uv_default_loop(), &request, (const char*) name, NULL); + uint64_t mode = request.statbuf.st_mode; + uv_fs_req_cleanup(&request); + + if (result != 0) { + return -1; + } else { + return (long) mode; + } +} + +/* + * Set file permission for 'name' to 'perm'. + * Returns FAIL for failure, OK otherwise. + */ +int mch_setperm(const char_u *name, int perm) +{ + uv_fs_t request; + int result = uv_fs_chmod(uv_default_loop(), &request, + (const char*)name, perm, NULL); + uv_fs_req_cleanup(&request); + + if (result != 0) { + return FAIL; + } else { + return OK; + } +} diff --git a/src/os/os.h b/src/os/os.h index 0d64f489cd..5a8c8fc005 100644 --- a/src/os/os.h +++ b/src/os/os.h @@ -17,5 +17,7 @@ int mch_get_usernames(garray_T *usernames); int mch_get_user_name(char *s, size_t len); int mch_get_uname(uid_t uid, char *s, size_t len); char *mch_get_user_directory(const char *name); +long mch_getperm(const char_u *name); +int mch_setperm(const char_u *name, int perm); #endif diff --git a/src/os_unix.c b/src/os_unix.c index 9ed034f4c1..c7e083a2d5 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1168,38 +1168,6 @@ int len; /* buffer size, only used when name gets longer */ } #endif -/* - * Get file permissions for 'name'. - * Returns -1 when it doesn't exist. - */ -long mch_getperm(char_u *name) -{ - struct stat statb; - - /* Keep the #ifdef outside of stat(), it may be a macro. */ - if (stat((char *)name, &statb)) - return -1; -#ifdef __INTERIX - /* The top bit makes the value negative, which means the file doesn't - * exist. Remove the bit, we don't use it. */ - return statb.st_mode & ~S_ADDACE; -#else - return statb.st_mode; -#endif -} - -/* - * set file permission for 'name' to 'perm' - * - * return FAIL for failure, OK otherwise - */ -int mch_setperm(char_u *name, long perm) -{ - return chmod((char *) - name, - (mode_t)perm) == 0 ? OK : FAIL; -} - #if defined(HAVE_ACL) || defined(PROTO) # ifdef HAVE_SYS_ACL_H # include <sys/acl.h> diff --git a/src/os_unix.h b/src/os_unix.h index 4db402c1e8..cc3eb4607a 100644 --- a/src/os_unix.h +++ b/src/os_unix.h @@ -28,8 +28,6 @@ void mch_get_host_name(char_u *s, int len); long mch_get_pid(void); void slash_adjust(char_u *p); void fname_case(char_u *name, int len); -long mch_getperm(char_u *name); -int mch_setperm(char_u *name, long perm); void mch_copy_sec(char_u *from_file, char_u *to_file); vim_acl_T mch_get_acl(char_u *fname); void mch_set_acl(char_u *fname, vim_acl_T aclent); @@ -41,6 +41,7 @@ #include "term.h" #include "ui.h" #include "window.h" +#include "os/os.h" /* * Structure to hold pointers to various items in a tag line. |