home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / tctnt / stdbin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-27  |  1.1 KB  |  32 lines

  1. /* STDBIN.C: example of binary redirection
  2.  
  3.          It is sometimes necessary to change stdin or stdout to binary
  4.          prior to redirection. For instance, redirecting a graphics
  5.          screen to a graphics capable printer would require such a
  6.          change.  This program demonstrates a method for accomplishing
  7.          this task.
  8. */
  9.  
  10. #include <stdio.h>            // for fileno(), stdout and fputc()
  11. #include <io.h>                    // for ioctl() and setmode(),
  12. #include <fcntl.h>            // for O_BINARY
  13.  
  14. // There are 3 things that need to be done.
  15.  
  16. //*******************************************************************
  17. int main(void)
  18. {
  19.     int     hndl = fileno( stdout );
  20.     int     info = ioctl( hndl, 0 );
  21.  
  22.     setmode( hndl, O_BINARY );               // handle to binary mode
  23.     ioctl( hndl, 1, (info & 0xff) | 0x20 );  // device to raw mode
  24.     stdout->flags |= _F_BIN;                 // stream to binary mode
  25.  
  26.     fputc('\n', stdout);
  27.                     //                               // your code goes here
  28.                     //
  29.     ioctl( hndl, 1, info & 0xff );           // restore original mode
  30.   return 0;
  31. } // end of main()
  32.