19 #define IN_REPLACEMENTS_C
33 void *t = malloc(
size);
35 memset(t, 0x00,
size);
41 void *t = malloc(
size);
48 memset(t, 0x55,
size);
63 size_t strnlen(
const char *s,
size_t maxlen)
65 const char *end = (
const char *)memchr(s,
'\0', maxlen);
66 return end ? (size_t) (end - s) : maxlen;
74 char *
new = malloc(len + 1);
80 return (
char *) memcpy(
new, s, len);
86 static bool safe_fd_isset(
int fd, fd_set *set)
91 int win_select(
int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds,
struct timeval *tv)
93 DWORD ms_total, limit;
94 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
95 int handle_slot_to_fd[MAXIMUM_WAIT_OBJECTS];
97 fd_set sock_read, sock_write, sock_except;
98 fd_set aread, awrite, aexcept;
107 ms_total = tv->
tv_sec * 1000;
108 ms_total += tv->
tv_usec / 1000;
112 FD_ZERO(&sock_write);
113 FD_ZERO(&sock_except);
118 if (rfds && rfds->fd_count == 0)
120 if (wfds && wfds->fd_count == 0)
122 if (efds && efds->fd_count == 0)
124 if (!rfds && !wfds && !efds && tv) {
131 for (i = 0; i < max_fd; i++) {
132 if (safe_fd_isset(i, rfds) || safe_fd_isset(i, wfds) || safe_fd_isset(i, efds)) {
133 intptr_t handle = (intptr_t) _get_osfhandle(i);
134 handles[n_handles] = (HANDLE)handle;
135 if (handles[n_handles] == INVALID_HANDLE_VALUE) {
137 if (safe_fd_isset(i, rfds))
139 if (safe_fd_isset(i, wfds))
141 if (safe_fd_isset(i, efds))
146 handle_slot_to_fd[n_handles] = i;
152 if (n_handles == 0) {
154 return select(max_fd, rfds, wfds, efds, tv);
164 limit = GetTickCount() + ms_total;
168 if (sock_max_fd >= 0) {
173 aexcept = sock_except;
176 tvslice.tv_usec = 1000;
178 retcode = select(sock_max_fd + 1, &aread, &awrite, &aexcept, &tvslice);
185 wret = MsgWaitForMultipleObjects(n_handles,
191 if (wret == WAIT_TIMEOUT) {
197 }
else if (wret == WAIT_FAILED) {
203 for (i = 0; i < n_handles; i++) {
204 if (WaitForSingleObject(handles[i], 0) == WAIT_OBJECT_0) {
205 if (safe_fd_isset(handle_slot_to_fd[i], rfds)) {
207 intptr_t handle = (intptr_t) _get_osfhandle(
208 handle_slot_to_fd[i]);
210 if (PeekNamedPipe((HANDLE)handle,
NULL, 0,
222 if (safe_fd_isset(handle_slot_to_fd[i], wfds)) {
226 if (safe_fd_isset(handle_slot_to_fd[i], efds)) {
234 }
while (retcode == 0 && (ms_total == INFINITE || GetTickCount() < limit));
uint32_t size
Size of dw_spi_transaction::buffer.
char * strndup(const char *s, size_t n)
void * clear_malloc(size_t size)
void * fill_malloc(size_t size)
size_t strnlen(const char *s, size_t maxlen)
#define OCD_FD_SET(fd, set)
#define OCD_FD_ISSET(fd, set)