32 #if _WIN32 || _POSIX_C_SOURCE >= 200112L
39 #pragma GCC diagnostic ignored "-Wformat"
40 #pragma GCC diagnostic ignored "-Wformat-extra-args"
43 static int pipe(HANDLE fildes[2]);
48 .fini = &default_fini,
49 .flags = &default_flags,
50 .read = &default_read,
51 .write = &default_write };
56 assert(handle_vector);
66 #if (defined(__CYGWIN__) || defined(__linux__)) && defined(_GNU_SOURCE)
67 if (pipe2(
fd, O_CLOEXEC) == -1) {
75 #if _POSIX_C_SOURCE >= 200112L && !defined(__CYGINW__) && !defined(__linux__)
76 if (fcntl(
fd[0], F_SETFD, FD_CLOEXEC) == -1) {
80 if (fcntl(
fd[1], F_SETFD, FD_CLOEXEC) == -1) {
87 if (!handle_vector[0]) {
89 goto error_alloc_handle_vector_0;
91 handle_vector[0]->
fd =
fd[0];
94 if (!handle_vector[1]) {
96 goto error_alloc_handle_vector_1;
98 handle_vector[1]->
fd =
fd[1];
105 error_alloc_handle_vector_1:
108 error_alloc_handle_vector_0:
110 #if _POSIX_C_SOURCE >= 200112L && !defined(__CYGINW__) && !defined(__linux__)
127 pipe(HANDLE fildes[2])
130 fildes[0] = fildes[1] = INVALID_HANDLE_VALUE;
134 CHAR Name[MAX_PATH] = { 0 };
136 snprintf(Name,
sizeof(Name) - 1,
137 "\\\\.\\pipe\\lely-io-pipe-%04lx-%08I64x",
138 GetCurrentProcessId(), InterlockedIncrement64(&cnt));
140 fildes[0] = CreateNamedPipeA(Name,
141 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
142 PIPE_TYPE_BYTE | PIPE_WAIT, 1, 1, 1, 0, NULL);
143 if (fildes[0] == INVALID_HANDLE_VALUE) {
144 dwErrCode = GetLastError();
145 goto error_CreateNamedPipeA;
148 fildes[1] = CreateFileA(Name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
149 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
150 if (fildes[1] == INVALID_HANDLE_VALUE) {
151 dwErrCode = GetLastError();
152 goto error_CreateFileA;
158 CloseHandle(fildes[0]);
159 fildes[0] = INVALID_HANDLE_VALUE;
160 error_CreateNamedPipeA:
161 SetLastError(dwErrCode);
166 #endif // _WIN32 || _POSIX_C_SOURCE >= 200112L
168 #endif // !LELY_NO_STDIO