Coverage Report

Created: 2026-03-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmGetPipes.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmGetPipes.h"
4
5
#include <cm3p/uv.h>
6
#include <fcntl.h>
7
8
#if defined(_WIN32) && !defined(__CYGWIN__)
9
#  include <io.h>
10
11
int cmGetPipes(int* fds)
12
{
13
  SECURITY_ATTRIBUTES attr;
14
  HANDLE readh, writeh;
15
  attr.nLength = sizeof(attr);
16
  attr.lpSecurityDescriptor = nullptr;
17
  attr.bInheritHandle = FALSE;
18
  if (!CreatePipe(&readh, &writeh, &attr, 0))
19
    return uv_translate_sys_error(GetLastError());
20
  fds[0] = _open_osfhandle((intptr_t)readh, 0);
21
  fds[1] = _open_osfhandle((intptr_t)writeh, 0);
22
  if (fds[0] == -1 || fds[1] == -1) {
23
    CloseHandle(readh);
24
    CloseHandle(writeh);
25
    return uv_translate_sys_error(GetLastError());
26
  }
27
  return 0;
28
}
29
#else
30
#  include <cerrno>
31
32
#  include <unistd.h>
33
34
int cmGetPipes(int* fds)
35
0
{
36
0
  if (pipe(fds) == -1) {
37
0
    return uv_translate_sys_error(errno);
38
0
  }
39
40
0
  if (fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
41
0
      fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) {
42
0
    close(fds[0]);
43
0
    close(fds[1]);
44
0
    return uv_translate_sys_error(errno);
45
0
  }
46
0
  return 0;
47
0
}
48
#endif