home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / select.c < prev    next >
C/C++ Source or Header  |  1993-02-22  |  846b  |  42 lines

  1. /*
  2.  * select() emulation for MiNT. Written by Eric R. Smith and placed in the
  3.  * public domain
  4.  */
  5.  
  6. #include <errno.h>
  7. #include <mintbind.h>
  8.  
  9. struct timeval {
  10.     long    tv_sec;
  11.     long    tv_usec;
  12. };
  13.  
  14. int
  15. select(junk, rfds, wfds, xfds, timeout)
  16.     int junk;
  17.     long *rfds, *wfds, *xfds;
  18.     struct timeval *timeout;
  19. {
  20. /* the only tricky part, really, is figuring out the timeout value.
  21.    a null pointer means indefinite timeout, which is the same as a 0
  22.    value under MiNT. A non-null pointer to a 0 valued struct means
  23.    to poll; in MiNT we simulate this with a minimum timeout value.
  24.  */
  25.     unsigned short mtime;
  26.     int rval;
  27.  
  28.     if (timeout) {
  29.         mtime = timeout->tv_sec * 1000 + timeout->tv_usec/1000;
  30.         if (mtime == 0) mtime = 1;
  31.     }
  32.     else
  33.         mtime = 0;
  34.  
  35.     rval = Fselect(mtime, rfds, wfds, xfds);
  36.     if (rval < 0) {
  37.         errno = -rval;
  38.         return -1;
  39.     }
  40.     return rval;
  41. }
  42.