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

  1. #include <errno.h>
  2. #include <io.h>
  3. #include <stddef.h>
  4. #include <termios.h>
  5. #include <sys/exceptn.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. tcsetattr (int handle, int action, const struct termios *termiosp)
  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.   /* check arguments */
  39.   if (termiosp == NULL)
  40.     {
  41.       errno = EINVAL;
  42.       return -1;
  43.     }
  44.  
  45.   /* set the structure */
  46.   switch (action)
  47.     {
  48.     case TCSANOW:
  49.     case TCSAFLUSH:
  50.     case TCSADRAIN:
  51.       /* enable or disable ^C */
  52.       if ((__libc_tty_p->t_lflag & ISIG) && ! (termiosp->c_iflag & IGNBRK)
  53.       && (termiosp->c_iflag & BRKINT) && (termiosp->c_cc[VINTR] == 0x03))
  54.     __djgpp_set_ctrl_c (1);
  55.       else
  56.     __djgpp_set_ctrl_c (0);
  57.  
  58.       /* copy the structure */
  59.       __libc_tty_p->t_termios = *termiosp;
  60.       break;
  61.     default:
  62.       errno = EINVAL;
  63.       return -1;
  64.     }
  65.  
  66.   return 0;
  67. }
  68.