home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / c / help.arc / SETRAW2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-11  |  1.7 KB  |  59 lines

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