summaryrefslogtreecommitdiff
path: root/src/libstddjb/iopause_ppoll.c
blob: 960a46411761ca0c83c141fbce43a7f04cbaa203 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* ISC license. */

#include <skalibs/sysdeps.h>

#ifdef SKALIBS_HASPPOLL

/* Just in case OpenBSD implements ppoll before fixing EOVERFLOW.
   Stranger things have happened in the wonderful world of OpenBSD. */
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <errno.h>
#include <time.h>
#include <poll.h>
#include <skalibs/tai.h>
#include <skalibs/iopause.h>

int iopause_ppoll (iopause_fd *x, unsigned int len, tain_t const *deadline, tain_t const *stamp)
{
  struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 } ;
  if (deadline && tain_less(stamp, deadline))
  {
    tain_t delta ;
    tain_sub(&delta, deadline, stamp) ;
    if (!timespec_from_tain_relative(&ts, &delta))
    {
      if (errno != EOVERFLOW) return -1 ;
      else deadline = 0 ;
    }
  }
  return ppoll(x, len, deadline ? &ts : 0, 0) ;
}

#else

#include <errno.h>
#include <skalibs/iopause.h>

int iopause_ppoll (iopause_fd *x, unsigned int len, tain_t const *deadline, tain_t const *stamp)
{
  (void)x ;
  (void)len ;
  (void)deadline ;
  (void)stamp ;
  return (errno = ENOSYS, -1) ;
}

#endif