From 509214d6696f4f061e61e328407630b7d26ebf8b Mon Sep 17 00:00:00 2001 From: Mustafa M Date: Tue, 4 Aug 2020 11:06:11 -0400 Subject: [PATCH] win,fs: use CreateDirectoryW instead of _wmkdir No functional changes are intended [NFCI], but this may make it easier in the future to implement and respect the `modes` flag. PR-URL: https://github.com/libuv/libuv/pull/2921 Reviewed-By: Jameson Nash --- src/win/fs.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/win/fs.c b/src/win/fs.c index 9577bc02..da0c2445 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -1221,12 +1221,12 @@ void fs__unlink(uv_fs_t* req) { void fs__mkdir(uv_fs_t* req) { /* TODO: use req->mode. */ - req->result = _wmkdir(req->file.pathw); - if (req->result == -1) { - req->sys_errno_ = _doserrno; - req->result = req->sys_errno_ == ERROR_INVALID_NAME - ? UV_EINVAL - : uv_translate_sys_error(req->sys_errno_); + if (CreateDirectoryW(req->file.pathw, NULL)) { + SET_REQ_RESULT(req, 0); + } else { + SET_REQ_WIN32_ERROR(req, GetLastError()); + if (req->sys_errno_ == ERROR_INVALID_NAME) + req->result = UV_EINVAL; } } @@ -1279,10 +1279,13 @@ void fs__mktemp(uv_fs_t* req, uv__fs_mktemp_func func) { static int fs__mkdtemp_func(uv_fs_t* req) { - if (_wmkdir(req->file.pathw) == 0) { + DWORD error; + if (CreateDirectoryW(req->file.pathw, NULL)) { SET_REQ_RESULT(req, 0); return 1; - } else if (errno != EEXIST) { + } + error = GetLastError(); + if (error != ERROR_ALREADY_EXISTS) { SET_REQ_RESULT(req, -1); return 1; }