FILE far *freopen (const char far *path, const char far *mode, FILE far *stream) { fclose(stream); if(open2 (fileno(stream), path, mflag(mode))==-1)return NULL; return stream; }
FILE far* fdopen (int h, char far *type) {FILE far *fp; fp=FCBS; fp+=h; FCBS[h].flag=mflag(type); return fp; }
FILE far *fopen (const char far *path, const char far *mode) {int h; FILE far *fp; if((h=open(path, mflag(mode)))==-1)return NULL; fp=FCBS; fp+=h; return fp; }
int execcmd(shinstance *psh, int argc, char **argv) { if (argc > 1) { struct strlist *sp; iflag(psh) = 0; /* exit on error */ mflag(psh) = 0; optschanged(psh); for (sp = psh->cmdenviron; sp; sp = sp->next) setvareq(psh, sp->text, VEXPORT|VSTACK); shellexec(psh, argv + 1, environment(psh), pathval(psh), 0, 0); } return 0; }
void setsignal(shinstance *psh, int signo, int vforked) { int action; shsig_t sigact = SH_SIG_DFL; char *t, tsig; if ((t = psh->trap[signo]) == NULL) action = S_DFL; else if (*t != '\0') action = S_CATCH; else action = S_IGN; if (psh->rootshell && !vforked && action == S_DFL) { switch (signo) { case SIGINT: if (iflag(psh) || psh->minusc || sflag(psh) == 0) action = S_CATCH; break; case SIGQUIT: #ifdef DEBUG if (debug(psh)) break; #endif /* FALLTHROUGH */ case SIGTERM: if (iflag(psh)) action = S_IGN; break; #if JOBS case SIGTSTP: case SIGTTOU: if (mflag(psh)) action = S_IGN; break; #endif } } t = &psh->sigmode[signo - 1]; tsig = *t; if (tsig == 0) { /* * current setting unknown */ if (!getsigaction(psh, signo, &sigact)) { /* * Pretend it worked; maybe we should give a warning * here, but other shells don't. We don't alter * sigmode, so that we retry every time. */ return; } if (sigact == SH_SIG_IGN) { if (mflag(psh) && (signo == SIGTSTP || signo == SIGTTIN || signo == SIGTTOU)) { tsig = S_IGN; /* don't hard ignore these */ } else tsig = S_HARD_IGN; } else { tsig = S_RESET; /* force to be set */ } } if (tsig == S_HARD_IGN || tsig == action) return; switch (action) { case S_DFL: sigact = SH_SIG_DFL; break; case S_CATCH: sigact = onsig; break; case S_IGN: sigact = SH_SIG_IGN; break; } if (!vforked) *t = action; sh_siginterrupt(psh, signo, 1); sh_signal(psh, signo, sigact); }