[BACK]Return to fio.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mail

Diff for /src/usr.bin/mail/fio.c between version 1.18 and 1.19

version 1.18, 2001/01/16 05:36:08 version 1.19, 2001/11/20 20:50:00
Line 57 
Line 57 
  * File I/O.   * File I/O.
  */   */
   
   static volatile sig_atomic_t fiosignal;
   
 /*  /*
  * Wrapper for read() to catch EINTR.   * Wrapper for read() to catch EINTR.
  */   */
Line 206 
Line 208 
  * include the newline (or carriage return) at the end.   * include the newline (or carriage return) at the end.
  */   */
 int  int
 readline(ibuf, linebuf, linesize)  readline(ibuf, linebuf, linesize, signo)
         FILE *ibuf;          FILE *ibuf;
         char *linebuf;          char *linebuf;
         int linesize;          int linesize;
           int *signo;
 {  {
           struct sigaction act;
           struct sigaction savetstp;
           struct sigaction savettou;
           struct sigaction savettin;
           struct sigaction saveint;
           struct sigaction savehup;
           sigset_t oset;
         int n;          int n;
   
           /*
            * Setup signal handlers if the caller asked us to catch signals.
            * Note that we do not restart system calls since we need the
            * read to be interuptible.
            */
           if (signo) {
                   fiosignal = 0;
                   sigemptyset(&act.sa_mask);
                   act.sa_flags = 0;
                   act.sa_handler = fioint;
                   if (sigaction(SIGINT, NULL, &saveint) == 0 &&
                       saveint.sa_handler != SIG_IGN) {
                           (void)sigaction(SIGINT, &act, &saveint);
                           (void)sigprocmask(SIG_UNBLOCK, &intset, &oset);
                   }
                   if (sigaction(SIGHUP, NULL, &savehup) == 0 &&
                       savehup.sa_handler != SIG_IGN)
                           (void)sigaction(SIGHUP, &act, &savehup);
                   (void)sigaction(SIGTSTP, &act, &savetstp);
                   (void)sigaction(SIGTTOU, &act, &savettou);
                   (void)sigaction(SIGTTIN, &act, &savettin);
           }
   
         clearerr(ibuf);          clearerr(ibuf);
         if (fgets(linebuf, linesize, ibuf) == NULL)          if (fgets(linebuf, linesize, ibuf) == NULL) {
                 return(-1);                  if (ferror(ibuf))
                           clearerr(ibuf);
                   n = -1;
           } else {
                   n = strlen(linebuf);
                   if (n > 0 && linebuf[n - 1] == '\n')
                           linebuf[--n] = '\0';
                   if (n > 0 && linebuf[n - 1] == '\r')
                           linebuf[--n] = '\0';
           }
   
         n = strlen(linebuf);          if (signo) {
         if (n > 0 && linebuf[n - 1] == '\n')                  (void)sigprocmask(SIG_SETMASK, &oset, NULL);
                 linebuf[--n] = '\0';                  (void)sigaction(SIGINT, &saveint, NULL);
         if (n > 0 && linebuf[n - 1] == '\r')                  (void)sigaction(SIGHUP, &savehup, NULL);
                 linebuf[--n] = '\0';                  (void)sigaction(SIGTSTP, &savetstp, NULL);
                   (void)sigaction(SIGTTOU, &savettou, NULL);
                   (void)sigaction(SIGTTIN, &savettin, NULL);
                   *signo = fiosignal;
           }
   
         return(n);          return(n);
 }  }
   
Line 340 
Line 387 
 }  }
   
 /*  /*
    * Unblock and ignore a signal
    */
   int
   ignoresig(sig, oact, oset)
           int sig;
           struct sigaction *oact;
           sigset_t *oset;
   {
           struct sigaction act;
           sigset_t nset;
           int error;
   
           sigemptyset(&act.sa_mask);
           act.sa_flags = SA_RESTART;
           act.sa_handler = SIG_IGN;
           error = sigaction(sig, &act, oact);
   
           if (error == 0) {
                   sigemptyset(&nset);
                   sigaddset(&nset, sig);
                   (void)sigprocmask(SIG_UNBLOCK, &nset, oset);
           } else if (oset != NULL)
                   (void)sigprocmask(SIG_BLOCK, NULL, oset);
   
           return(error);
   }
   
   /*
  * Determine the size of the file possessed by   * Determine the size of the file possessed by
  * the passed buffer.   * the passed buffer.
  */   */
Line 492 
Line 567 
                 cp = expand(buf);                  cp = expand(buf);
         }          }
         return(cp);          return(cp);
   }
   
   /*
    * Signal handler used by readline() to catch SIGINT, SIGHUP, SIGTSTP,
    * SIGTTOU, SIGTTIN.
    */
   void
   fioint(s)
           int s;
   {
   
           fiosignal = s;
 }  }

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19