1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: 
   7: /*
   8:  * isfg() determines whether a process is a foreground job and standard
   9:  * input stream is connected to a terminal. Returns integer YES if it is,
  10:  * otherwise NO.
  11:  */
  12: #include <stdio.h>
  13: #include <signal.h>
  14: #include <sys/ioctl.h>
  15: #include "system.h"
  16: #include "yesno.h"
  17: 
  18: isfg()
  19: {
  20:     int isfg = NO;          /* is foreground? */
  21: #ifdef V4BSD
  22:     int isatty();           /* is stream a terminal? */
  23:     int tpgrp;          /* terminal process group */
  24:     int (*tstpstat)();      /* stop signal status */
  25:     int (*ttinstat)();      /* background read status */
  26:     int (*ttoustat)();      /* background write status */
  27: 
  28:     tstpstat = signal(SIGTSTP, SIG_IGN);
  29:     ttinstat = signal(SIGTTIN, SIG_IGN);
  30:     ttoustat = signal(SIGTTOU, SIG_IGN);
  31:     if (isatty(fileno(stdin)))
  32:         {
  33:         ioctl(fileno(stdin), TIOCGPGRP, &tpgrp);
  34:         if (tpgrp == getpgrp(0))
  35:             isfg = YES;
  36:         }
  37:     signal(SIGTSTP, tstpstat);
  38:     signal(SIGTTIN, ttinstat);
  39:     signal(SIGTTOU, ttoustat);
  40: #else
  41:     int isatty();           /* is stream a terminal? */
  42: 
  43:     if (isatty(fileno(stdin)))
  44:         isfg = YES;
  45: #endif
  46:     return(isfg);
  47: }

Defined functions

isfg defined in line 18; used 4 times
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 563
Valid CSS Valid XHTML 1.0 Strict