File: sortpfd.h

package info (click to toggle)
ngetty 1.0-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 304 kB
  • ctags: 207
  • sloc: ansic: 1,503; makefile: 236; sh: 109; asm: 100
file content (21 lines) | stat: -rw-r--r-- 425 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}