aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-06-14 13:15:07 -0400
committerJustin M. Keyes <justinkz@gmail.com>2014-07-14 09:04:54 -0400
commit180c84ed378e694ebcd14198a7436e01462d2c4d (patch)
tree899919991e7586a279d4704e9904afc602544494 /src/nvim/os
parentbf6b0e3c0aa34beca13eee898decdf0fcde8b502 (diff)
downloadrneovim-180c84ed378e694ebcd14198a7436e01462d2c4d.tar.gz
rneovim-180c84ed378e694ebcd14198a7436e01462d2c4d.tar.bz2
rneovim-180c84ed378e694ebcd14198a7436e01462d2c4d.zip
os_open: impl mch_open with libuv. ref #133
- use return value instead of open_req.result - libuv uv_fs_open() returns `-errno` instead of always -1 - libuv always sets open_req.result to the return value, _except_ for OOM where it only sets the return value. So always use the return value. - replace calls to mch_open macro. - update call sites expecting -1 error
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/fs.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index c1cb418d5c..ff8b8557de 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -11,6 +11,7 @@
#include "nvim/misc2.h"
#include "nvim/path.h"
#include "nvim/strings.h"
+#include "nvim/log.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/fs.c.generated.h"
@@ -150,6 +151,24 @@ static bool is_executable_in_path(const char_u *name)
return false;
}
+/// Opens or creates a file and returns a non-negative integer representing
+/// the lowest-numbered unused file descriptor, for use in subsequent system
+/// calls (read, write, lseek, fcntl, etc.). If the operation fails, `-errno`
+/// is returned, and no file is created or modified.
+///
+/// @param flags bitwise OR of flags defined in <fcntl.h>
+/// @param mode permissions for the newly-created file (IGNORED if 'flags' is
+/// not `O_CREAT` or `O_TMPFILE`)
+/// @return file descriptor, or negative `errno` on failure
+int os_open(const char* path, int flags, int mode)
+{
+ uv_fs_t open_req;
+ int r = uv_fs_open(uv_default_loop(), &open_req, path, flags, mode, NULL);
+ uv_fs_req_cleanup(&open_req);
+ //`r` is the same as open_req.result, except when OOM. So just use `r`.
+ return r;
+}
+
/// Get stat information for a file.
///
/// @return OK on success, FAIL if a failure occurred.
@@ -291,7 +310,7 @@ int os_remove(const char *path)
/// Get the file information for a given path
///
-/// @param file_descriptor File descriptor of the file.
+/// @param path Path to the file.
/// @param[out] file_info Pointer to a FileInfo to put the information in.
/// @return `true` on success, `false` for failure.
bool os_get_file_info(const char *path, FileInfo *file_info)