summaryrefslogtreecommitdiffstats
path: root/test/test_ext.c.in
blob: f2dbb8228a69218bc77099ad0d9b9ff3282b994e (plain)
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
33
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

int main ()
{
  char line[256];
  int  flags;
  FILE * foo = fopen ("MYPWDIR", "a");

  flags = fcntl(STDIN_FILENO, F_GETFL);
  fcntl(STDIN_FILENO, F_SETFL, flags|O_NONBLOCK);

 xagain:	
  errno = 0;
  while (NULL != fgets(line, 255, stdin))
    {
      fprintf (foo, "RECV: %s", line);
      fflush  (foo);
    } 
  if (ferror(stdin) && errno == EAGAIN) 
    {
      clearerr(stdin);
      goto xagain;
    }
  fclose(foo);
  return 0;
}