tcflow.c: tcflow implementation
authorFaisal Abbas <90.abbasfaisal@gmail.com>
Sun, 15 Mar 2015 13:05:26 +0000 (13:05 +0000)
committerAlan Cox <alan@linux.intel.com>
Sun, 15 Mar 2015 16:11:53 +0000 (16:11 +0000)
Library/libs/tcflow.c

index 27d8492..d062b67 100644 (file)
@@ -4,7 +4,24 @@
 
 int tcflow(int fd, int action)
 {
-       /* TODO */
-       errno = EINVAL;
-       return -1;
+       struct termios term;
+       cc_t c;
+
+       switch (action) {
+               case TCOOFF:
+                       return ioctl(fd, TIOCOSTOP, 0);
+               case TCOON:
+                       return ioctl(fd, TIOCOSTART, 0);
+               case TCIOFF:
+               case TCION:
+                       if (tcgetattr(fd, &term) == -1)
+                               return -1;
+                       c = term.c_cc[action == TCIOFF ? VSTOP : VSTART];
+                       if (c != _POSIX_VDISABLE && (write(fd, &c, sizeof(c))) == -1)
+                               return -1;
+                       return 0;
+               default:
+                       errno = EINVAL;
+                       return -1;
+       }
 }