File: badtest.c

package info (click to toggle)
fte 0.50.0-1.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,536 kB
  • ctags: 6,167
  • sloc: cpp: 45,854; ansic: 2,586; perl: 808; makefile: 125; sh: 104
file content (32 lines) | stat: -rw-r--r-- 819 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

/* GNU INDENT - po endif */
int rawio_getc (rawio_t * rawio, int *c) {
  char buf;
  fd_set rfds;
  struct timeval tv;

  tv.tv_sec = rawio->tout_sec;
  tv.tv_usec = rawio->tout_usec;
  FD_ZERO (&rfds);
  FD_SET (rawio->io_fd, &rfds);

  if (select (rawio->io_fd + 1, &rfds, NULL, NULL, &tv))
    {
#ifdef DEBUG
    {
      double t;
      t = (rawio->tout_sec - tv.tv_sec) +
	(0.000001 * (rawio->tout_usec - tv.tv_usec));
      fprintf (stderr, "DEBUG rawio_getc buffer has data, time from "
	       "previous %gs\n", t);
    }
#endif
  if (read (rawio->io_fd, &buf, 1) != 1)
    return 0;           /* unknown error... 'select' said
    there was a byte in the buffer
    but read could not read it */
  *c = buf;
  return 1;                     // success
    }
  return 0;                     // timeout occoured
}