home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PJ8_3.ZIP / STD_TST.C < prev    next >
C/C++ Source or Header  |  1990-01-22  |  937b  |  34 lines

  1. /*   std_tst.c   std_tst function
  2. *    Tests whether stdin or stdout has been
  3. *    redirected to a file  
  4. *    Written by: B. H. Robinson
  5. *       Written: Jan 21, 1990
  6. *       Version: 001
  7. *    The parameter "channel" must be 0 to test stdin or
  8. *    1 to test stdout. stdin_tst returns 0 if the channel
  9. *    is redirected to a file, 1 if it is a device or -1
  10. *    if there is an error in execution of std_tst.
  11. *********************************************/
  12. #include <stdio.h>
  13. #include <io.h>
  14. #include <conio.h>
  15.  
  16. int std_tst( int channel )
  17. {
  18.     int stat;
  19.  
  20.     if( (channel != 0) && (channel != 1) ) {
  21.         cprintf( "Incorrect parameter in call to std_tst.\n\r");
  22.         return -1;
  23.     }
  24.     stat = ioctl( channel, 0 );
  25.     if( stat == -1 )
  26.         return -1;
  27.     if( (stat & 0x80) == 128 )
  28.         return 1;
  29.     else
  30.         return 0;
  31. }    
  32. /************** end of file ****************************/
  33.  
  34.