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__) 71 #if _POSIX_C_SOURCE >= 200112L && !defined(__CYGINW__) && !defined(__linux__) 72 if (
__unlikely(fcntl(
fd[0], F_SETFD, FD_CLOEXEC) == -1)) {
76 if (
__unlikely(fcntl(
fd[1], F_SETFD, FD_CLOEXEC) == -1)) {
85 goto error_alloc_handle_vector_0;
87 handle_vector[0]->
fd =
fd[0];
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 (
__unlikely(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 (
__unlikely(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 This header file is part of the I/O library; it contains the pipe declarations.
int io_open_pipe(io_handle_t handle_vector[2])
Opens a pipe.
This is the internal header file of the default implementation of the I/O device handle methods...
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...
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
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 get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function...
The virtual table of an I/O device handle.
#define __unlikely(x)
Indicates to the compiler that the expression is most-likely false.
This is the internal header file of the I/O library.
This header file is part of the C11 and POSIX compatibility library; it includes <stdio.h> and defines any missing functionality.
int fd
The native file descriptor.
struct io_handle * io_handle_alloc(const struct io_handle_vtab *vtab)
Allocates a new I/O device handle from a virtual table.
void io_handle_free(struct io_handle *handle)
Frees an I/O device handle.