+ if (t->pend) {
+ t->pend->t = 0;
+ t->pend = 0;
+ }
+}
+
+/* --- @sel_addhook@ --- *
+ *
+ * Arguments: @sel_state *s@ = pointer to state block
+ * @sel_hook *h@ = pointer to hook block
+ * @sel_hookfn before, after@ = hook functions
+ * @void *p@ = pointer argument to pass to hook functions
+ *
+ * Returns: ---
+ *
+ * Use: Registers hook functions to be called on each select call.
+ */
+
+void sel_addhook(sel_state *s, sel_hook *h,
+ sel_hookfn before, sel_hookfn after,
+ void *p)
+{
+ h->before = before;
+ h->after = after;
+ h->p = p;
+ h->next = s->hooks;
+ h->prev = (sel_hook *)&s->hooks;
+ if (s->hooks)
+ s->hooks->prev = h;
+ s->hooks = h;
+}
+
+/* --- @sel_rmhook@ --- *
+ *
+ * Arguments: @sel_hook *h@ = pointer to hook block
+ *
+ * Returns: ---
+ *
+ * Use: Removes hook functions.
+ */
+
+void sel_rmhook(sel_hook *h)
+{
+ if (h->next)
+ h->next->prev = h->prev;
+ h->prev->next = h->next;
+}
+
+/* --- @sel_fdmerge@ --- *
+ *
+ * Arguments: @fd_set *dest@ = destination FD set
+ * @fd_set *fd@ = pointer to set to merge
+ * @int maxfd@ = highest numbered descriptor in @fd@ + 1
+ *
+ * Returns: Actual highest numbered descriptor.
+ *
+ * Use: Merges file descriptor sets, and returns an accurate @maxfd@
+ * value.
+ */
+
+int sel_fdmerge(fd_set *dest, fd_set *fd, int maxfd)
+{
+ int i, m = -1;
+
+ for (i = 0; i < maxfd; i++) {
+ if (FD_ISSET(i, fd)) {
+ FD_SET(i, dest);
+ m = i;
+ }
+ }
+
+ return (m + 1);