24 void *t = malloc(
size);
26 memset(t, 0x00,
size);
32 void *t = malloc(
size);
39 memset(t, 0x55,
size);
44 #define IN_REPLACEMENTS_C
58 #ifndef HAVE_GETTIMEOFDAY
64 #define EPOCHFILETIME (116444736000000000i64)
66 #define EPOCHFILETIME (116444736000000000LL)
77 GetSystemTimeAsFileTime(&ft);
78 li.LowPart = ft.dwLowDateTime;
79 li.HighPart = ft.dwHighDateTime;
83 tv->
tv_sec = (long)(t / 1000000);
84 tv->
tv_usec = (long)(t % 1000000);
92 tz->tz_minuteswest = _timezone / 60;
93 tz->tz_dsttime = _daylight;
105 const char *end = (
const char *)memchr(s,
'\0', maxlen);
106 return end ? (size_t) (end - s) : maxlen;
114 char *
new = malloc(len + 1);
120 return (
char *) memcpy(
new, s, len);
125 int win_select(
int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds,
struct timeval *tv)
127 DWORD ms_total, limit;
128 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
129 int handle_slot_to_fd[MAXIMUM_WAIT_OBJECTS];
130 int n_handles = 0, i;
131 fd_set sock_read, sock_write, sock_except;
132 fd_set aread, awrite, aexcept;
133 int sock_max_fd = -1;
137 #define SAFE_FD_ISSET(fd, set) (set && FD_ISSET(fd, set))
143 ms_total = tv->
tv_sec * 1000;
144 ms_total += tv->
tv_usec / 1000;
148 FD_ZERO(&sock_write);
149 FD_ZERO(&sock_except);
152 for (i = 0; i < max_fd; i++) {
153 if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
154 intptr_t handle = (intptr_t) _get_osfhandle(i);
155 handles[n_handles] = (HANDLE)handle;
156 if (handles[n_handles] == INVALID_HANDLE_VALUE) {
158 if (SAFE_FD_ISSET(i, rfds))
159 FD_SET(i, &sock_read);
160 if (SAFE_FD_ISSET(i, wfds))
161 FD_SET(i, &sock_write);
162 if (SAFE_FD_ISSET(i, efds))
163 FD_SET(i, &sock_except);
167 handle_slot_to_fd[n_handles] = i;
173 if (n_handles == 0) {
175 return select(max_fd, rfds, wfds, efds, tv);
185 limit = GetTickCount() + ms_total;
189 if (sock_max_fd >= 0) {
194 aexcept = sock_except;
197 tvslice.tv_usec = 1000;
199 retcode = select(sock_max_fd + 1, &aread, &awrite, &aexcept, &tvslice);
206 wret = MsgWaitForMultipleObjects(n_handles,
212 if (wret == WAIT_TIMEOUT) {
218 }
else if (wret == WAIT_FAILED) {
224 for (i = 0; i < n_handles; i++) {
225 if (WaitForSingleObject(handles[i], 0) == WAIT_OBJECT_0) {
226 if (SAFE_FD_ISSET(handle_slot_to_fd[i], rfds)) {
228 intptr_t handle = (intptr_t) _get_osfhandle(
229 handle_slot_to_fd[i]);
231 if (PeekNamedPipe((HANDLE)handle,
NULL, 0,
235 FD_SET(handle_slot_to_fd[i], &aread);
239 FD_SET(handle_slot_to_fd[i], &aread);
243 if (SAFE_FD_ISSET(handle_slot_to_fd[i], wfds)) {
244 FD_SET(handle_slot_to_fd[i], &awrite);
247 if (SAFE_FD_ISSET(handle_slot_to_fd[i], efds)) {
248 FD_SET(handle_slot_to_fd[i], &aexcept);
255 }
while (retcode == 0 && (ms_total == INFINITE || GetTickCount() < limit));
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)
size_t size
Size of the control block search area.