+ +
a18b27f fix(windows): resolve Win32 Winsock, signal, and CLI test compatibility
saifmukhtar · 2026-11-24
main
| 1 | /* |
| 2 | * SPDX-License-Identifier: AGPL-3.0-or-later WITH Classpath-exception-2.0 |
| 3 | * Copyright (c) 2026 Saif Mukhtar |
| 4 | * |
| 5 | * OpenAVX - Open Audio-Video eXchange |
| 6 | * include/compat/win32/sys/uio.h - Win32 emulation of sys/uio.h |
| 7 | */ |
| 8 | |
| 9 | #ifndef OPENAVX_COMPAT_WIN32_SYS_UIO_H |
| 10 | #define OPENAVX_COMPAT_WIN32_SYS_UIO_H |
| 11 | |
| 12 | #if defined(_WIN32) || defined(_MSC_VER) |
| 13 | |
| 14 | #ifndef WIN32_LEAN_AND_MEAN |
| 15 | #define WIN32_LEAN_AND_MEAN |
| 16 | #endif |
| 17 | #include <winsock2.h> |
| 18 | #include <ws2tcpip.h> |
| 19 | #include <stddef.h> |
| 20 | |
| 21 | struct iovec { |
| 22 | void *iov_base; |
| 23 | size_t iov_len; |
| 24 | }; |
| 25 | |
| 26 | static inline int writev(int fd, const struct iovec *iov, int iovcnt) { |
| 27 | if (!iov || iovcnt <= 0) return -1; |
| 28 | int total = 0; |
| 29 | for (int i = 0; i < iovcnt; i++) { |
| 30 | int n = send((SOCKET)fd, (const char*)iov[i].iov_base, (int)iov[i].iov_len, 0); |
| 31 | if (n < 0) { |
| 32 | return (total > 0) ? total : -1; |
| 33 | } |
| 34 | total += n; |
| 35 | if ((size_t)n < iov[i].iov_len) break; |
| 36 | } |
| 37 | return total; |
| 38 | } |
| 39 | |
| 40 | #endif /* __MINGW32__ vs _MSC_VER */ |
| 41 | |
| 42 | #endif /* OPENAVX_COMPAT_WIN32_SYS_UIO_H */ |