os_open, os_stat: UV_EINVAL on NULL filename

EINVAL (instead of EFAULT) because that's what glibc does:
https://github.com/bminor/glibc/blob/master/io/open.c#L35

os_nodetype: check for UV_EINVAL explicitly.

ref #4370
ref https://github.com/neovim/neovim/issues/4370#issuecomment-344366571
ref ac055d677a

ref #4772
This commit is contained in:
Justin M. Keyes 2017-11-14 22:59:58 +01:00
parent 07931ed1c8
commit d135ba99b2

View File

@ -172,7 +172,7 @@ int os_nodetype(const char *name)
| O_NONBLOCK | O_NONBLOCK
#endif #endif
, 0); , 0);
if (fd == -1) { if (fd == UV_EINVAL) {
return NODE_OTHER; // open() failed. return NODE_OTHER; // open() failed.
} }
@ -394,9 +394,11 @@ end:
/// @param mode Permissions for the newly-created file (IGNORED if 'flags' is /// @param mode Permissions for the newly-created file (IGNORED if 'flags' is
/// not `O_CREAT` or `O_TMPFILE`), subject to the current umask /// not `O_CREAT` or `O_TMPFILE`), subject to the current umask
/// @return file descriptor, or libuv error code on failure /// @return file descriptor, or libuv error code on failure
int os_open(const char* path, int flags, int mode) int os_open(const char *path, int flags, int mode)
FUNC_ATTR_NONNULL_ALL
{ {
if (path == NULL) { // uv_fs_open asserts on NULL. #7561
return UV_EINVAL;
}
int r; int r;
RUN_UV_FS_FUNC(r, uv_fs_open, path, flags, mode, NULL); RUN_UV_FS_FUNC(r, uv_fs_open, path, flags, mode, NULL);
return r; return r;
@ -603,12 +605,12 @@ int os_fsync(int fd)
/// Get stat information for a file. /// Get stat information for a file.
/// ///
/// @return libuv return code. /// @return libuv return code, or -errno
static int os_stat(const char *name, uv_stat_t *statbuf) static int os_stat(const char *name, uv_stat_t *statbuf)
FUNC_ATTR_NONNULL_ARG(2) FUNC_ATTR_NONNULL_ARG(2)
{ {
if (!name) { if (!name) {
return UV_ENOENT; return UV_EINVAL;
} }
uv_fs_t request; uv_fs_t request;
int result = uv_fs_stat(&fs_loop, &request, name, NULL); int result = uv_fs_stat(&fs_loop, &request, name, NULL);