19 #define IN_REPLACEMENTS_C
32 void *t = malloc(
size);
34 memset(t, 0x00,
size);
40 void *t = malloc(
size);
47 memset(t, 0x55,
size);
62 #ifndef HAVE_GETTIMEOFDAY
68 #define EPOCHFILETIME (116444736000000000i64)
70 #define EPOCHFILETIME (116444736000000000LL)
81 GetSystemTimeAsFileTime(&ft);
82 li.LowPart = ft.dwLowDateTime;
83 li.HighPart = ft.dwHighDateTime;
87 tv->
tv_sec = (long)(t / 1000000);
88 tv->
tv_usec = (long)(t % 1000000);
96 tz->tz_minuteswest = _timezone / 60;
97 tz->tz_dsttime = _daylight;
109 const char *end = (
const char *)memchr(s,
'\0', maxlen);
110 return end ? (size_t) (end - s) : maxlen;
118 char *
new = malloc(len + 1);
124 return (
char *) memcpy(
new, s, len);
129 int win_select(
int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds,
struct timeval *tv)
131 DWORD ms_total, limit;
132 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
133 int handle_slot_to_fd[MAXIMUM_WAIT_OBJECTS];
134 int n_handles = 0, i;
135 fd_set sock_read, sock_write, sock_except;
136 fd_set aread, awrite, aexcept;
137 int sock_max_fd = -1;
141 #define SAFE_FD_ISSET(fd, set) (set && FD_ISSET(fd, set))
147 ms_total = tv->
tv_sec * 1000;
148 ms_total += tv->
tv_usec / 1000;
152 FD_ZERO(&sock_write);
153 FD_ZERO(&sock_except);
158 if (rfds && rfds->fd_count == 0)
160 if (wfds && wfds->fd_count == 0)
162 if (efds && efds->fd_count == 0)
164 if (!rfds && !wfds && !efds && tv) {
171 for (i = 0; i < max_fd; i++) {
172 if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
173 intptr_t handle = (intptr_t) _get_osfhandle(i);
174 handles[n_handles] = (HANDLE)handle;
175 if (handles[n_handles] == INVALID_HANDLE_VALUE) {
177 if (SAFE_FD_ISSET(i, rfds))
178 FD_SET(i, &sock_read);
179 if (SAFE_FD_ISSET(i, wfds))
180 FD_SET(i, &sock_write);
181 if (SAFE_FD_ISSET(i, efds))
182 FD_SET(i, &sock_except);
186 handle_slot_to_fd[n_handles] = i;
192 if (n_handles == 0) {
194 return select(max_fd, rfds, wfds, efds, tv);
204 limit = GetTickCount() + ms_total;
208 if (sock_max_fd >= 0) {
213 aexcept = sock_except;
216 tvslice.tv_usec = 1000;
218 retcode = select(sock_max_fd + 1, &aread, &awrite, &aexcept, &tvslice);
225 wret = MsgWaitForMultipleObjects(n_handles,
231 if (wret == WAIT_TIMEOUT) {
237 }
else if (wret == WAIT_FAILED) {
243 for (i = 0; i < n_handles; i++) {
244 if (WaitForSingleObject(handles[i], 0) == WAIT_OBJECT_0) {
245 if (SAFE_FD_ISSET(handle_slot_to_fd[i], rfds)) {
247 intptr_t handle = (intptr_t) _get_osfhandle(
248 handle_slot_to_fd[i]);
250 if (PeekNamedPipe((HANDLE)handle,
NULL, 0,
254 FD_SET(handle_slot_to_fd[i], &aread);
258 FD_SET(handle_slot_to_fd[i], &aread);
262 if (SAFE_FD_ISSET(handle_slot_to_fd[i], wfds)) {
263 FD_SET(handle_slot_to_fd[i], &awrite);
266 if (SAFE_FD_ISSET(handle_slot_to_fd[i], efds)) {
267 FD_SET(handle_slot_to_fd[i], &aexcept);
274 }
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)
int gettimeofday(struct timeval *tv, struct timezone *tz)