home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / posix / termios / tcflow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-15  |  1.4 KB  |  72 lines

  1. #include <libc/stubs.h>
  2. #include <errno.h>
  3. #include <io.h>
  4. #include <termios.h>
  5. #include <unistd.h>
  6. #include <libc/bss.h>
  7. #include <libc/ttyprvt.h>
  8.  
  9. #define _DEV_STDIN  0x0001
  10. #define _DEV_STDOUT 0x0002
  11. #define _DEV_NUL    0x0004
  12. #define _DEV_CLOCK  0x0008
  13. #define _DEV_RAW    0x0020
  14. #define _DEV_CDEV   0x0080
  15. #define _DEV_IOCTRL 0x4000
  16.  
  17. int
  18. tcflow (int handle, int action)
  19. {
  20.   short devmod;
  21.  
  22.   /* initialize */
  23.   if (__libc_termios_hook_common_count != __bss_count)
  24.     __libc_termios_init ();
  25.  
  26.   /* check handle whether valid or not */
  27.   devmod = _get_dev_info (handle);
  28.   if (devmod == -1)
  29.     return -1;
  30.  
  31.   /* check console */
  32.   if (! (devmod & _DEV_CDEV) || ! (devmod & (_DEV_STDIN|_DEV_STDOUT)))
  33.     {
  34.       errno = ENOTTY;
  35.       return -1;
  36.     }
  37.  
  38.   /* flow control */
  39.   switch (action)
  40.     {
  41.     case TCOOFF:
  42.     case TCOON:
  43.       /* nothing */
  44.       break;
  45.     case TCIOFF:
  46.     case TCION:
  47.       {
  48.     struct termios termiosbuf;
  49.     unsigned char c;
  50.  
  51.     /* get the structure */
  52.     if (tcgetattr (handle, &termiosbuf) == -1)
  53.       return -1;
  54.  
  55.     /* get flow character */
  56.     c = termiosbuf.c_cc[(action == TCIOFF) ? VSTOP : VSTART];
  57.     if (c != (unsigned char) _POSIX_VDISABLE)
  58.       {
  59.         /* now write on handle */
  60.         if (write (handle, &c, 1) < 0)
  61.           return -1;
  62.       }
  63.       }
  64.       break;
  65.     default:
  66.       errno = EINVAL;
  67.       return -1;
  68.     }
  69.  
  70.   return 0;
  71. }
  72.