| 304 | #endif /* !MinGW */ |
| 305 | |
| 306 | int |
| 307 | poll (struct pollfd *pfd, nfds_t nfd, int timeout) |
| 308 | { |
| 309 | #ifndef WIN32_NATIVE |
| 310 | fd_set rfds, wfds, efds; |
| 311 | struct timeval tv; |
| 312 | struct timeval *ptv; |
| 313 | int maxfd, rc; |
| 314 | nfds_t i; |
| 315 | |
| 316 | # ifdef _SC_OPEN_MAX |
| 317 | static int sc_open_max = -1; |
| 318 | |
| 319 | if (nfd < 0 |
| 320 | || (nfd > sc_open_max |
| 321 | && (sc_open_max != -1 |
| 322 | || nfd > (sc_open_max = sysconf (_SC_OPEN_MAX))))) |
| 323 | { |
| 324 | errno = EINVAL; |
| 325 | return -1; |
| 326 | } |
| 327 | # else /* !_SC_OPEN_MAX */ |
| 328 | # ifdef OPEN_MAX |
| 329 | if (nfd < 0 || nfd > OPEN_MAX) |
| 330 | { |
| 331 | errno = EINVAL; |
| 332 | return -1; |
| 333 | } |
| 334 | # endif /* OPEN_MAX -- else, no check is needed */ |
| 335 | # endif /* !_SC_OPEN_MAX */ |
| 336 | |
| 337 | /* EFAULT is not necessary to implement, but let's do it in the |
| 338 | simplest case. */ |
| 339 | if (!pfd && nfd) |
| 340 | { |
| 341 | errno = EFAULT; |
| 342 | return -1; |
| 343 | } |
| 344 | |
| 345 | /* convert timeout number into a timeval structure */ |
| 346 | if (timeout == 0) |
| 347 | { |
| 348 | ptv = &tv; |
| 349 | ptv->tv_sec = 0; |
| 350 | ptv->tv_usec = 0; |
| 351 | } |
| 352 | else if (timeout > 0) |
| 353 | { |
| 354 | ptv = &tv; |
| 355 | ptv->tv_sec = timeout / 1000; |
| 356 | ptv->tv_usec = (timeout % 1000) * 1000; |
| 357 | } |
| 358 | else if (timeout == INFTIM) |
| 359 | /* wait forever */ |
| 360 | ptv = NULL; |
| 361 | else |
| 362 | { |
| 363 | errno = EINVAL; |
no test coverage detected