28 #if defined(_WIN32) || _POSIX_C_SOURCE >= 200112L
35 #pragma GCC diagnostic ignored "-Wformat"
36 #pragma GCC diagnostic ignored "-Wformat-extra-args"
39 static int pipe(HANDLE fildes[2]);
44 .fini = &default_fini,
45 .flags = &default_flags,
46 .read = &default_read,
47 .write = &default_write };
52 assert(handle_vector);
62 #if (defined(__CYGWIN__) || defined(__linux__)) && defined(_GNU_SOURCE)
63 if (pipe2(
fd, O_CLOEXEC) == -1) {
71 #if _POSIX_C_SOURCE >= 200112L && !defined(__CYGINW__) && !defined(__linux__)
72 if (fcntl(
fd[0], F_SETFD, FD_CLOEXEC) == -1) {
76 if (fcntl(
fd[1], F_SETFD, FD_CLOEXEC) == -1) {
83 if (!handle_vector[0]) {
85 goto error_alloc_handle_vector_0;
87 handle_vector[0]->
fd =
fd[0];
90 if (!handle_vector[1]) {
92 goto error_alloc_handle_vector_1;
94 handle_vector[1]->
fd =
fd[1];
101 error_alloc_handle_vector_1:
104 error_alloc_handle_vector_0:
106 #if _POSIX_C_SOURCE >= 200112L && !defined(__CYGINW__) && !defined(__linux__)
123 pipe(HANDLE fildes[2])
126 fildes[0] = fildes[1] = INVALID_HANDLE_VALUE;
130 CHAR Name[MAX_PATH] = { 0 };
132 snprintf(Name,
sizeof(Name) - 1,
133 "\\\\.\\pipe\\lely-io-pipe-%04lx-%08I64x",
134 GetCurrentProcessId(), InterlockedIncrement64(&cnt));
136 fildes[0] = CreateNamedPipeA(Name,
137 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
138 PIPE_TYPE_BYTE | PIPE_WAIT, 1, 1, 1, 0, NULL);
139 if (fildes[0] == INVALID_HANDLE_VALUE) {
140 dwErrCode = GetLastError();
141 goto error_CreateNamedPipeA;
144 fildes[1] = CreateFileA(Name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
145 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
146 if (fildes[1] == INVALID_HANDLE_VALUE) {
147 dwErrCode = GetLastError();
148 goto error_CreateFileA;
154 CloseHandle(fildes[0]);
155 fildes[0] = INVALID_HANDLE_VALUE;
156 error_CreateNamedPipeA:
157 SetLastError(dwErrCode);
162 #endif // _WIN32 || _POSIX_C_SOURCE >= 200112L