Return libuv error code from os_getperm()

Previously os_getperms() returned -1 for any error condition, it
now returns the libuv error code (as returned by os_stat()). This
allows checking for error conditions without relying on errno
(which not available in Windows).

The only case where the errno value from os_getperms() was being used
was in readfile() to set the new-file flag - replaced the errno check
with UV_ENOENT.
This commit is contained in:
Rui Abreu Ferreira
2015-10-27 11:37:50 +00:00
parent 091b6e216c
commit d54338f1e0
2 changed files with 5 additions and 8 deletions

View File

@@ -535,11 +535,7 @@ readfile (
if (!newfile) { if (!newfile) {
return FAIL; return FAIL;
} }
if (perm < 0 if (perm == UV_ENOENT) {
#ifdef ENOENT
&& errno == ENOENT
#endif
) {
/* /*
* Set the 'new-file' flag, so that when the file has * Set the 'new-file' flag, so that when the file has
* been created by someone else, a ":w" will complain. * been created by someone else, a ":w" will complain.

View File

@@ -217,15 +217,16 @@ static int os_stat(const char *name, uv_stat_t *statbuf)
/// Get the file permissions for a given file. /// Get the file permissions for a given file.
/// ///
/// @return `-1` when `name` doesn't exist. /// @return libuv error code on error.
int32_t os_getperm(const char_u *name) int32_t os_getperm(const char_u *name)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
uv_stat_t statbuf; uv_stat_t statbuf;
if (os_stat((char *)name, &statbuf) == kLibuvSuccess) { int stat_result = os_stat((char *)name, &statbuf);
if (stat_result == kLibuvSuccess) {
return (int32_t)statbuf.st_mode; return (int32_t)statbuf.st_mode;
} else { } else {
return -1; return stat_result;
} }
} }