diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2019-04-16 21:55:39 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2019-04-25 16:03:08 (GMT) |
commit | c0e6b22d0a81c0e0dc1ee87366790882a3d54667 (patch) | |
tree | aec3b72bcbc27ece5336083d2f3314cfadbd1005 /Source/cmGetPipes.cxx | |
parent | 4ccf40e61e02cffb28b549a3de6f4794ea3e3d92 (diff) | |
download | CMake-c0e6b22d0a81c0e0dc1ee87366790882a3d54667.zip CMake-c0e6b22d0a81c0e0dc1ee87366790882a3d54667.tar.gz CMake-c0e6b22d0a81c0e0dc1ee87366790882a3d54667.tar.bz2 |
Refactor: Move/rename cmProcessGetPipes() to cmGetPipes()
Diffstat (limited to 'Source/cmGetPipes.cxx')
-rw-r--r-- | Source/cmGetPipes.cxx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Source/cmGetPipes.cxx b/Source/cmGetPipes.cxx new file mode 100644 index 0000000..ad323f7 --- /dev/null +++ b/Source/cmGetPipes.cxx @@ -0,0 +1,48 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmGetPipes.h" + +#include "cm_uv.h" + +#include <fcntl.h> + +#if defined(_WIN32) && !defined(__CYGWIN__) +# include <io.h> + +int cmGetPipes(int* fds) +{ + SECURITY_ATTRIBUTES attr; + HANDLE readh, writeh; + attr.nLength = sizeof(attr); + attr.lpSecurityDescriptor = nullptr; + attr.bInheritHandle = FALSE; + if (!CreatePipe(&readh, &writeh, &attr, 0)) + return uv_translate_sys_error(GetLastError()); + fds[0] = _open_osfhandle((intptr_t)readh, 0); + fds[1] = _open_osfhandle((intptr_t)writeh, 0); + if (fds[0] == -1 || fds[1] == -1) { + CloseHandle(readh); + CloseHandle(writeh); + return uv_translate_sys_error(GetLastError()); + } + return 0; +} +#else +# include <errno.h> +# include <unistd.h> + +int cmGetPipes(int* fds) +{ + if (pipe(fds) == -1) { + return uv_translate_sys_error(errno); + } + + if (fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 || + fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) { + close(fds[0]); + close(fds[1]); + return uv_translate_sys_error(errno); + } + return 0; +} +#endif |