diff options
| author | Klaatu Sverige <[email protected]> | 2015-08-05 21:31:21 +0000 |
|---|---|---|
| committer | Klaatu Sverige <[email protected]> | 2015-08-05 21:31:21 +0000 |
| commit | 86f0721bd904d8163c5f8f2472b78169146cc67d (patch) | |
| tree | cf9e61bd495c73ece45b96242e6f575af228d01d /riemann.fmi.uni-sofia.bg/ngetty/ngetty-1.1/sortpfd.h | |
| parent | 75a501d32dff3c1c1ee9a2a3dc6d5b704cc7c6d1 (diff) | |
added website data, because it had heaps of good tutorials and info
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.h | 21 |
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; +} |
