os_open: add unit tests

This commit is contained in:
Justin M. Keyes
2014-06-30 02:23:41 -04:00
parent 180c84ed37
commit 0ceebc2c91
4 changed files with 77 additions and 14 deletions

View File

@@ -11,7 +11,6 @@
#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"
@@ -156,16 +155,16 @@ static bool is_executable_in_path(const char_u *name)
/// 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`)
/// @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`), subject to the current umask
/// @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`.
// r is the same as open_req.result (except for OOM: then only r is set).
return r;
}