Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <errno.h>
- #include <sys/time.h>
- #include <sys/resource.h>
- int
- main ()
- {
- char x;
- int ret = 0;
- long fails = 0;
- int fd = 0;
- int flags = 0;
- unsigned long dataprocessed = 0;
- fd = fileno (stdin);
- flags = fcntl (fd, F_GETFL, 0);
- flags |= O_NONBLOCK;
- fcntl (fd, F_SETFL, flags);
- while (1)
- {
- ret = fread (&x, sizeof (char), 1, stdin);
- if (ret <= 0 && errno == EAGAIN)
- {
- /* No data to recieve */
- printf ("Error read file: %s\n", strerror (errno));
- continue;
- }
- if (errno == EWOULDBLOCK && ret == 0)
- {
- //printf("BLOCKING \n\r");
- fails++;
- }
- else
- {
- if (ret > 0)
- {
- /* data flows */
- fwrite (&x, sizeof (x), 1, stdout);
- fails = 0;
- //printf("ret: %d\n\r",sizeof(x));
- dataprocessed++;
- }
- }
- if (fails > 500000)
- {
- printf ("%d FAILURES DETECTED %ld bytes Processed\n\r", fails,
- dataprocessed);
- exit (0);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment