home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 15a / nansi987.zip / SETRAW.C < prev   
C/C++ Source or Header  |  1987-09-13  |  2KB  |  69 lines

  1. /*_ setraw.c   Sat Sep 12 1987   Modified by: Pat Myrto */
  2. /*------ setraw.lc ----------------------------------------------
  3. Microsoft C routines which get and set the current raw/cooked state
  4. of a file, given its DOS file descriptor.
  5. Useful when trying to obtain high console output speeds.
  6. ----------------------------------------------------------------*/
  7.  
  8. #include <dos.h>
  9.  
  10. #define CARRY 0x1
  11. #define ERROR (-1)
  12. #define TRUE 1
  13. #define FALSE 0
  14.  
  15.  
  16. /*---- getraw --------------------------------------------------
  17. Returns TRUE if file fd is a device in raw mode; FALSE otherwise.
  18. Returns ERROR, errorcode is in _doserrno, if DOS error.
  19. ----------------------------------------------------------------*/
  20. getraw(fd)
  21. int fd;
  22. {
  23.     union REGS inregs;
  24.     union REGS outregs;
  25.     int    flags;
  26.  
  27. /*    if (fd > 2) fd+=2;        /* convert to DOS fd */
  28.     inregs.x.bx = fd;
  29.     inregs.x.ax = 0x4400;        /* get file attributes */
  30.     flags = intdos(&inregs, &outregs);
  31.     if (outregs.x.cflag) return -1;
  32.  
  33.     return (outregs.x.dx & 0x20) ? TRUE : FALSE;
  34. }
  35. /*---- setraw --------------------------------------------------
  36. Sets Raw state of file fd to raw_on (if file is not a device, does nothing).
  37. Returns zero if successful.
  38. Returns ERROR & errorcode in _doserror if DOS error.
  39. ----------------------------------------------------------------*/
  40. setraw(fd, raw_on)
  41. int fd, raw_on;
  42. {
  43.     union REGS inregs;
  44.     union REGS outregs;
  45.  
  46.  
  47.     inregs.x.ax = 0x4400;        /* get file attributes */
  48.     inregs.x.bx = fd;
  49.  
  50.     intdos(&inregs, &outregs);
  51.  
  52.     if (outregs.x.cflag) return ERROR;
  53.  
  54.     if ((outregs.x.ax & 0x80) == 0)    /* return zero if not device */
  55.         return 0;
  56.  
  57.     outregs.x.ax = 0x4401;        /* set file attributes */
  58.     outregs.x.bx = fd;
  59.     outregs.x.dx &= 0xcf;        /* clear old raw bit & hi byte */
  60.     if (raw_on) outregs.x.dx |= 0x20;    /* maybe set new raw bit */
  61.  
  62.     intdos(&outregs, &inregs);
  63.  
  64.     if (outregs.x.cflag) return ERROR;
  65.  
  66.     return 0;
  67. }
  68. /*-- end of setraw.c --*/
  69.