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);
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.