32#if _WIN32 || _POSIX_C_SOURCE >= 200112L
39#pragma GCC diagnostic ignored "-Wformat"
40#pragma GCC diagnostic ignored "-Wformat-extra-args"
43static 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];
105error_alloc_handle_vector_1:
108error_alloc_handle_vector_0:
110#if _POSIX_C_SOURCE >= 200112L && !defined(__CYGINW__) && !defined(__linux__)
127pipe(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;
160error_CreateNamedPipeA:
161 SetLastError(dwErrCode);
This is the internal header file of the default implementation of the I/O device handle methods.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
void io_handle_free(struct io_handle *handle)
Frees an I/O device handle.
struct io_handle * io_handle_alloc(const struct io_handle_vtab *vtab)
Allocates a new I/O device handle from a virtual table.
io_handle_t io_handle_acquire(io_handle_t handle)
Increments the reference count of an I/O device handle.
#define IO_HANDLE_ERROR
The value of an invalid I/O device handle.
int io_open_pipe(io_handle_t handle_vector[2])
Opens a pipe.
This header file is part of the I/O library; it contains the pipe declarations.
This is the internal header file of the Windows-specific I/O declarations.
This header file is part of the C11 and POSIX compatibility library; it includes <stdio....
The virtual table of an I/O device handle.
int type
The type of the device (one of IO_TYPE_CAN, IO_TYPE_FILE, IO_TYPE_PIPE, IO_TYPE_SERIAL or IO_TYPE_SOC...
int fd
The native file descriptor.