summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibuv/src/unix/pipe.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-01-22 15:18:39 (GMT)
committerKitware Robot <kwrobot@kitware.com>2018-01-22 15:18:44 (GMT)
commit63f263b27fa9b9c63f038ff108118726bc9c5c64 (patch)
tree7022b7804d75353ed9d32570dff17b8ffe71feaf /Utilities/cmlibuv/src/unix/pipe.c
parentc81ace7ab7e5e325fef9339ed3ea05abbd0f8be4 (diff)
parent6db7b35236b81a73047a47c0f70f8befbf2ca51f (diff)
downloadCMake-63f263b27fa9b9c63f038ff108118726bc9c5c64.zip
CMake-63f263b27fa9b9c63f038ff108118726bc9c5c64.tar.gz
CMake-63f263b27fa9b9c63f038ff108118726bc9c5c64.tar.bz2
Merge topic 'update-libuv'
6db7b352 libuv: Update build within CMake b58d48c1 Merge branch 'upstream-libuv' into update-libuv f4a26c74 libuv 2018-01-19 (63de1eca) e8b57c22 libuv: Teach import script to add missing newlines Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1666
Diffstat (limited to 'Utilities/cmlibuv/src/unix/pipe.c')
-rw-r--r--Utilities/cmlibuv/src/unix/pipe.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/Utilities/cmlibuv/src/unix/pipe.c b/Utilities/cmlibuv/src/unix/pipe.c
index e3d436d..df3aad0 100644
--- a/Utilities/cmlibuv/src/unix/pipe.c
+++ b/Utilities/cmlibuv/src/unix/pipe.c
@@ -300,3 +300,56 @@ uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle) {
else
return uv__handle_type(handle->accepted_fd);
}
+
+
+int uv_pipe_chmod(uv_pipe_t* handle, int mode) {
+ unsigned desired_mode;
+ struct stat pipe_stat;
+ char* name_buffer;
+ size_t name_len;
+ int r;
+
+ if (handle == NULL || uv__stream_fd(handle) == -1)
+ return -EBADF;
+
+ if (mode != UV_READABLE &&
+ mode != UV_WRITABLE &&
+ mode != (UV_WRITABLE | UV_READABLE))
+ return -EINVAL;
+
+ if (fstat(uv__stream_fd(handle), &pipe_stat) == -1)
+ return -errno;
+
+ desired_mode = 0;
+ if (mode & UV_READABLE)
+ desired_mode |= S_IRUSR | S_IRGRP | S_IROTH;
+ if (mode & UV_WRITABLE)
+ desired_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
+
+ /* Exit early if pipe already has desired mode. */
+ if ((pipe_stat.st_mode & desired_mode) == desired_mode)
+ return 0;
+
+ pipe_stat.st_mode |= desired_mode;
+
+ /* Unfortunately fchmod does not work on all platforms, we will use chmod. */
+ name_len = 0;
+ r = uv_pipe_getsockname(handle, NULL, &name_len);
+ if (r != UV_ENOBUFS)
+ return r;
+
+ name_buffer = uv__malloc(name_len);
+ if (name_buffer == NULL)
+ return UV_ENOMEM;
+
+ r = uv_pipe_getsockname(handle, name_buffer, &name_len);
+ if (r != 0) {
+ uv__free(name_buffer);
+ return r;
+ }
+
+ r = chmod(name_buffer, pipe_stat.st_mode);
+ uv__free(name_buffer);
+
+ return r != -1 ? 0 : -errno;
+}