#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
+#include <errno.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/time.h>
extern char *safe_strdup(const char *string, const char *message);
extern void *safe_malloc(size_t size, const char *message);
extern void *safe_malloc_ary(size_t size, size_t count, const char *message);
+extern void *safe_realloc_ary(void *p, size_t size, size_t count,
+ const char *message);
void setcloexec(int fd); /* cannot fail */
void pipe_cloexec(int fd[2]); /* pipe(), setcloexec() twice; cannot fail */
int *timeout_io);
typedef void afterpoll_fn(void *st, struct pollfd *fds, int nfds);
+/* void BEFOREPOLL_WANT_FDS(int want);
+ * Expects: int *nfds_io;
+ * Can perform non-local exit.
+ * Checks whether there is space for want fds. If so, sets *nfds_io.
+ * If not, sets *nfds_io and returns. */
+#define BEFOREPOLL_WANT_FDS(want) do{ \
+ if (*nfds_io<(want)) { *nfds_io=(want); return ERANGE; } \
+ *nfds_io=(want); \
+ }while(0)
+
/* Register interest in the main loop of the program. Before a call
to poll() your supplied beforepoll function will be called. After
the call to poll() the supplied afterpoll function will be called.