From 91ca6788bbed45e758ee2744a61f8cf455932763 Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Tue, 15 Jan 2019 12:07:51 -0600 Subject: [PATCH] ibmi: return EISDIR on read from directory fd On IBM i PASE, EOPNOTSUPP is returned when reading a directory instead of EISDIR, like (seemingly) every other platform which doesn't support reading directories. To ensure compatibility with software expecting EISDIR, we map the EOPNOTSUPP to EISDIR when the fd passed in was a directory. This is a partial revert of 25a3894, but scoped to PASE and the fstat call is moved to the end so it's out of the fast path. Refs: https://github.com/nodejs/node/issues/25433 Fixes: https://github.com/libuv/libuv/issues/2147 PR-URL: https://github.com/libuv/libuv/pull/2148 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig --- src/unix/fs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/unix/fs.c b/src/unix/fs.c index a0bd70d04ca..91bb82f725e 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -317,6 +317,18 @@ static ssize_t uv__fs_read(uv_fs_t* req) { req->bufs = NULL; req->nbufs = 0; +#ifdef __PASE__ + /* PASE returns EOPNOTSUPP when reading a directory, convert to EISDIR */ + if (result == -1 && errno == EOPNOTSUPP) { + struct stat buf; + ssize_t rc; + rc = fstat(req->file, &buf); + if (rc == 0 && S_ISDIR(buf.st_mode)) { + errno = EISDIR; + } + } +#endif + return result; }