home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / utilslib / utils_old / c / Isatty < prev    next >
Encoding:
Text File  |  1994-02-22  |  828 b   |  35 lines

  1. /* C.Isatty: Test a stream to check whether it is 'interactive' */
  2.  
  3. /* Paul: this is probably wrong: isatty() takes an int fd as a parameter, not
  4.          a FILE *; fortunately with the scheme i'm using of equating fd's with
  5.          casted FILE *'s, this will probably work...  -- GT */
  6.  
  7. #include <stdio.h>
  8. #include "kernel.h"
  9.  
  10. #define RISCOSfileno(fp) ((int *)fp)[5]
  11.  
  12. int isatty (FILE *fp)
  13. {
  14.     _kernel_swi_regs r;
  15.  
  16.     /* If fp == NULL, say non-interactive... */
  17.     if (fp == NULL)
  18.         return 0;
  19.  
  20.     /* If we cannot seek on fp, the file is probably (?) a terminal,
  21.      * and so interactive.
  22.      */
  23.     if (fseek (fp, 0, SEEK_CUR) != 0)
  24.         return 1;
  25.  
  26.     /* We can seek, so we are a normal file. Does the OS think
  27.      * that fp is interactive?
  28.      */
  29.     r.r[0] = 254;
  30.     r.r[1] = RISCOSfileno(fp);
  31.     _kernel_swi(0x09,&r,&r);
  32.  
  33.     return ((r.r[0] & 8) == 8);
  34. }
  35.