aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/os/fs.c32
-rw-r--r--src/os/os.h6
2 files changed, 24 insertions, 14 deletions
diff --git a/src/os/fs.c b/src/os/fs.c
index 84e31502ab..489109bc24 100644
--- a/src/os/fs.c
+++ b/src/os/fs.c
@@ -1,7 +1,5 @@
// fs.c -- filesystem access
-#include <uv.h>
-
#include "os/os.h"
#include "message.h"
#include "misc1.h"
@@ -235,18 +233,28 @@ static int is_executable_in_path(const char_u *name)
return FALSE;
}
-int32_t os_getperm(const char_u *name)
+int os_stat(const char_u *name, uv_stat_t *statbuf)
{
uv_fs_t request;
int result = uv_fs_stat(uv_default_loop(), &request,
(const char *)name, NULL);
- uint64_t mode = request.statbuf.st_mode;
+ *statbuf = request.statbuf;
uv_fs_req_cleanup(&request);
- if (result != 0) {
+ if (result == 0) {
+ return OK;
+ } else {
+ return FAIL;
+ }
+}
+
+int32_t os_getperm(const char_u *name)
+{
+ uv_stat_t statbuf;
+ if (os_stat(name, &statbuf) == FAIL) {
return -1;
} else {
- return (int32_t) mode;
+ return (int32_t)statbuf.st_mode;
}
}
@@ -266,15 +274,11 @@ int os_setperm(const char_u *name, int perm)
int os_file_exists(const char_u *name)
{
- uv_fs_t request;
- int result = uv_fs_stat(uv_default_loop(), &request,
- (const char *)name, NULL);
- uv_fs_req_cleanup(&request);
-
- if (result != 0) {
- return FALSE;
- } else {
+ uv_stat_t statbuf;
+ if (os_stat(name, &statbuf) == OK) {
return TRUE;
+ } else {
+ return FALSE;
}
}
diff --git a/src/os/os.h b/src/os/os.h
index 452c053868..a319b02343 100644
--- a/src/os/os.h
+++ b/src/os/os.h
@@ -1,5 +1,6 @@
#ifndef NEOVIM_OS_OS_H
#define NEOVIM_OS_OS_H
+#include <uv.h>
#include "vim.h"
@@ -81,4 +82,9 @@ 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);
+/// Get stat information for a file.
+///
+/// @return OK on success, FAIL if an failure occured.
+int os_stat(const char_u *name, uv_stat_t *statbuf);
+
#endif // NEOVIM_OS_OS_H