home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / utilslib / c / Isatty < prev    next >
Encoding:
Text File  |  1990-05-14  |  595 b   |  31 lines

  1. /* C.Isatty: Test a stream to check whether it is 'interactive' */
  2.  
  3. #include <stdio.h>
  4. #include "kernel.h"
  5.  
  6. #define fileno(fp) ((int *)fp)[5]
  7.  
  8. int isatty (FILE *fp)
  9. {
  10.     _kernel_swi_regs r;
  11.  
  12.     /* If fp == NULL, say non-interactive... */
  13.     if (fp == NULL)
  14.         return 0;
  15.  
  16.     /* If we cannot seek on fp, the file is probably (?) a terminal,
  17.      * and so interactive.
  18.      */
  19.     if (fseek (fp, 0, SEEK_CUR) != 0)
  20.         return 1;
  21.  
  22.     /* We can seek, so we are a normal file. Does the OS think
  23.      * that fp is interactive?
  24.      */
  25.     r.r[0] = 254;
  26.     r.r[1] = fileno(fp);
  27.     _kernel_swi(0x09,&r,&r);
  28.  
  29.     return ((r.r[0] & 8) == 8);
  30. }
  31.