aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/sortpfd.h
diff options
context:
space:
mode:
Diffstat (limited to 'riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/sortpfd.h')
-rw-r--r--riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/sortpfd.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/sortpfd.h b/riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/sortpfd.h
new file mode 100644
index 0000000..7f3ec73
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/sortpfd.h
@@ -0,0 +1,21 @@
+static void swap_bytes(void *a, void *b, int len) {
+ char *x = a, *y = b, z;
+ while (len--) {
+ z = *x; *x = *y; *y = z;
+ ++x; ++y;
+ }
+}
+
+static int sortpfd() {
+ int l=0, r=npfd-1;
+ again:
+ while (l <= r && pfd[l].fd >= 0) ++l;
+ while (l <= r && pfd[r].fd < 0) --r;
+
+ if (l < r) {
+ swap_bytes(pfd+l, pfd+r, sizeof(pollfd_));
+ swap_bytes(tty+l, tty+r, sizeof(tty_name_));
+ goto again;
+ }
+ return l;
+}