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

  1. #include <errno.h>
  2. #include <io.h>
  3. #include <termios.h>
  4. #include <libc/bss.h>
  5. #include <libc/ttyprvt.h>
  6.  
  7. #define _DEV_STDIN  0x0001
  8. #define _DEV_STDOUT 0x0002
  9. #define _DEV_NUL    0x0004
  10. #define _DEV_CLOCK  0x0008
  11. #define _DEV_RAW    0x0020
  12. #define _DEV_CDEV   0x0080
  13. #define _DEV_IOCTRL 0x4000
  14.  
  15. int
  16. tcflush (int handle, int which)
  17. {
  18.   short devmod;
  19.  
  20.   /* initialize */
  21.   if (__libc_termios_hook_common_count != __bss_count)
  22.     __libc_termios_init ();
  23.  
  24.   /* check handle whether valid or not */
  25.   devmod = _get_dev_info (handle);
  26.   if (devmod == -1)
  27.     return -1;
  28.  
  29.   /* check console */
  30.   if (! (devmod & _DEV_CDEV) || ! (devmod & (_DEV_STDIN|_DEV_STDOUT)))
  31.     {
  32.       errno = ENOTTY;
  33.       return -1;
  34.     }
  35.  
  36.   /* flush ... */
  37.   switch (which)
  38.     {
  39.     case TCIFLUSH:
  40.     case TCIOFLUSH:
  41.       /* clear input queue */
  42.       if (__libc_tty_p->t_count != 0)
  43.     {
  44.       __libc_tty_p->t_count = 0;
  45.       __libc_tty_p->t_rpos = __libc_tty_p->t_top;
  46.       __libc_tty_p->t_wpos = __libc_tty_p->t_top;
  47.     }
  48.       break;
  49.     case TCOFLUSH:
  50.       /* nothing */
  51.       break;
  52.     default:
  53.       errno = EINVAL;
  54.       return -1;
  55.     }
  56.  
  57.   return 0;
  58. }
  59.