From 77eda8d90b51c8a654f97fd8d2c32ccc8280191a Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Wed, 11 Nov 2015 13:18:31 +0200 Subject: [PATCH] win: properly return UV_EBADF when _close() fails Previously, libuv didn't return the correct error code when attempting to close an invalid file descriptor with `uv_fs_close()`. PR-URL: https://github.com/libuv/libuv/pull/613 Reviewed-by: Bert Belder --- src/win/fs.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/win/fs.c b/src/win/fs.c index 4a175731..fe56dba6 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -533,7 +533,15 @@ void fs__close(uv_fs_t* req) { else result = 0; - SET_REQ_RESULT(req, result); + /* _close doesn't set _doserrno on failure, but it does always set errno + * to EBADF on failure. + */ + if (result == -1) { + assert(errno == EBADF); + SET_REQ_UV_ERROR(req, UV_EBADF, ERROR_INVALID_HANDLE); + } else { + req->result = 0; + } }