rem: milliseconds = msToNextTimerEvent(); timeout.tv_sec = milliseconds / 1000; timeout.tv_usec = (milliseconds % 1000) * 1000;
add: delayUntilNextTimerEvent(&timeout);
context: W_WaitForEvent(Display *dpy, unsigned long xeventmask){#ifndef HAVE_SELECT#error This_system_does_not_have_select(2)_and_is_not_supported#endif    unsigned long milliseconds;    struct timeval timeout;    struct timeval *timeoutPtr;    fd_set rset, wset, eset;    int maxfd;    int count;    InputHandler *handler = inputHandler;    FD_ZERO(&rset);    FD_ZERO(&wset);    FD_ZERO(&eset);    FD_SET(ConnectionNumber(dpy), &rset);    maxfd = ConnectionNumber(dpy);    while (handler) {	if (handler->mask & WIReadMask)	    FD_SET(handler->fd, &rset);	if (handler->mask & WIWriteMask)	    FD_SET(handler->fd, &wset);	if (handler->mask & WIExceptMask)	    FD_SET(handler->fd, &eset);	if (maxfd < handler->fd)	    maxfd = handler->fd;	handler = handler->next;    }    /*     * Setup the select() timeout to the estimated time until the     * next timer expires.     */    if (timerPending()) {	milliseconds = msToNextTimerEvent();	timeout.tv_sec = milliseconds / 1000;	timeout.tv_usec = (milliseconds % 1000) * 1000;	timeoutPtr = &timeout;    } else {	timeoutPtr = (struct timeval*)0;    }    XSync(dpy, False);    if (xeventmask==0) {	if (XPending(dpy))	    return True;    } else {	XEvent ev;	if (XCheckMaskEvent(dpy, xeventmask, &ev)) {	    XPutBackEvent(dpy, &ev);	    return True;	}    }    /* TODO: port to poll() */    count = select(1 + maxfd, &rset, &wset, &eset, timeoutPtr);    if (count > 0) {	handler = inputHandler;	while (handler) {	    int mask;	    mask = 0;	    if (FD_ISSET(handler->fd, &rset))		mask |= WIReadMask;	    	    if (FD_ISSET(handler->fd, &wset))		mask |= WIWriteMask;	    	    if (FD_ISSET(handler->fd, &eset))		mask |= WIExceptMask;	    	    if (mask!=0 && handler->callback) {		(*handler->callback)(handler->fd, mask, 				     handler->clientData);	    }	    handler = handler->next;	}    }        return FD_ISSET(ConnectionNumber(dpy), &rset);}