From 180c84ed378e694ebcd14198a7436e01462d2c4d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 14 Jun 2014 13:15:07 -0400 Subject: 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 --- src/nvim/os/fs.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/nvim/os') 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 +/// @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) -- cgit