From 9614d5113526ba82bc8522b0b1c9a119e45932d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 27 Dec 2012 23:15:40 +0100 Subject: [PATCH] unix: reset errno when using sendfile emulation A common way to check if a uv_fs_t request failed is to check that req->errorno != 0. With uv_fs_sendfile(), when the sendfile() syscall fails, req->errorno is set to (for example) ENOTSOCK, even when the emulation code path succeeds. Zero errno before the call to uv__fs_sendfile_emul() to prevent that from happening. --- src/unix/fs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/unix/fs.c b/src/unix/fs.c index 6c6faf53..f01c83b4 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -381,6 +381,7 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { errno == EIO || errno == ENOTSOCK || errno == EXDEV) { + errno = 0; return uv__fs_sendfile_emul(req); } @@ -412,6 +413,7 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { errno == EIO || errno == ENOTSOCK || errno == EXDEV) { + errno = 0; return uv__fs_sendfile_emul(req); }