1: /*
   2: char id_system[] = "@(#)system_.c	1.5";
   3:  *
   4:  * execute a unix command
   5:  *
   6:  * calling sequence:
   7:  *	iexit = system(command)
   8:  * where:
   9:  *	iexit will return the exit status of the command
  10:  *	command is a character string containing the command to be executed
  11:  */
  12: 
  13: #include    "../libI77/fiodefs.h"
  14: #include    <sys/param.h>
  15: #ifndef NCARGS
  16: #define NCARGS  256
  17: #endif
  18: 
  19: 
  20: ftnint system_(s, n)
  21: char *s;
  22: ftnlen n;
  23: {
  24:     char buf[NCARGS - 50];
  25:     ftnint i;
  26: 
  27:     if (n >= sizeof buf)
  28:         return(-(ftnint)(errno=F_ERARG));
  29:     for (i = 0; i < MXUNIT; i++)
  30:         flush_(&i);
  31:     g_char(s, n, buf);
  32:     return((ftnint)system(buf));
  33: }
  34: 
  35: /*
  36:  * this is a sane version of the libc/stdio routine.
  37:  */
  38: 
  39: #include    <signal.h>
  40: 
  41: char    *getenv();
  42: char    *rindex();
  43: 
  44: system(s)
  45: char *s;
  46: {
  47:     register int (*istat)(), (*qstat)();
  48:     int status, pid, w;
  49:     char    *shname, *shell;
  50: 
  51:     if ((shell = getenv("SHELL")) == NULL)
  52:         shell = "/bin/sh";
  53: 
  54:     if (shname = rindex(shell, '/'))
  55:         shname++;
  56:     else
  57:         shname = shell;
  58: 
  59:     if ((pid = fork()) == 0) {
  60:         execl(shell, shname, "-c", s, 0);
  61:         _exit(127);
  62:     }
  63:     istat = signal(SIGINT, SIG_IGN);
  64:     qstat = signal(SIGQUIT, SIG_IGN);
  65:     while ((w = wait(&status)) != pid && w != -1)
  66:         ;
  67:     if (w == -1)
  68:         status = -1;
  69:     signal(SIGINT, istat);
  70:     signal(SIGQUIT, qstat);
  71:     return((ftnint) status);
  72: }

Defined functions

system defined in line 44; used 1 times
  • in line 32
system_ defined in line 20; never used

Defined macros

NCARGS defined in line 16; used 2 times
Last modified: 1983-07-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 730
Valid CSS Valid XHTML 1.0 Strict