aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-30 12:42:24 +0100
committerRon Yorston <rmy@pobox.com>2012-03-30 12:42:24 +0100
commit4319368c60244268a19f58fd6f1a0b31d3cd4853 (patch)
treea511501ed8bcc73ab24e0c5e5f9280ba713e7495 /win32/mingw.c
parent506360df73c9c9f95f4caf70373673cf55046c9d (diff)
downloadbusybox-w32-4319368c60244268a19f58fd6f1a0b31d3cd4853.tar.gz
busybox-w32-4319368c60244268a19f58fd6f1a0b31d3cd4853.tar.bz2
busybox-w32-4319368c60244268a19f58fd6f1a0b31d3cd4853.zip
Use gnulib poll, importing the version from git
Diffstat (limited to 'win32/mingw.c')
-rw-r--r--win32/mingw.c69
1 files changed, 0 insertions, 69 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 0a7345374..df413d18e 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -421,75 +421,6 @@ int pipe(int filedes[2])
421 return 0; 421 return 0;
422} 422}
423 423
424int poll(struct pollfd *ufds, unsigned int nfds, int timeout)
425{
426 int i, pending;
427
428 if (timeout >= 0) {
429 if (nfds == 0) {
430 Sleep(timeout);
431 return 0;
432 }
433 errno = EINVAL;
434 return -1;
435 }
436
437 /* When there is only one fd to wait for, then we pretend that
438 * input is available and let the actual wait happen when the
439 * caller invokes read().
440 */
441 if (nfds == 1) {
442 if (!(ufds[0].events & POLLIN)) {
443 errno = EINVAL;
444 return -1;
445 }
446 ufds[0].revents = POLLIN;
447 return 0;
448 }
449
450repeat:
451 pending = 0;
452 for (i = 0; i < nfds; i++) {
453 DWORD avail = 0;
454 HANDLE h = (HANDLE) _get_osfhandle(ufds[i].fd);
455 if (h == INVALID_HANDLE_VALUE)
456 return -1; /* errno was set */
457
458 if (!(ufds[i].events & POLLIN)) {
459 errno = EINVAL;
460 return -1;
461 }
462
463 /* this emulation works only for pipes */
464 if (!PeekNamedPipe(h, NULL, 0, NULL, &avail, NULL)) {
465 int err = GetLastError();
466 if (err == ERROR_BROKEN_PIPE) {
467 ufds[i].revents = POLLHUP;
468 pending++;
469 } else {
470 errno = EINVAL;
471 return -1;
472 }
473 } else if (avail) {
474 ufds[i].revents = POLLIN;
475 pending++;
476 } else
477 ufds[i].revents = 0;
478 }
479 if (!pending) {
480 /* The only times that we spin here is when the process
481 * that is connected through the pipes is waiting for
482 * its own input data to become available. But since
483 * the process (pack-objects) is itself CPU intensive,
484 * it will happily pick up the time slice that we are
485 * relinguishing here.
486 */
487 Sleep(0);
488 goto repeat;
489 }
490 return 0;
491}
492
493struct tm *gmtime_r(const time_t *timep, struct tm *result) 424struct tm *gmtime_r(const time_t *timep, struct tm *result)
494{ 425{
495 /* gmtime() in MSVCRT.DLL is thread-safe, but not reentrant */ 426 /* gmtime() in MSVCRT.DLL is thread-safe, but not reentrant */