[BACK]Return to popen.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gen

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libc/gen/popen.c between version 1.7 and 1.8

version 1.7, 1994/05/06 18:44:25 version 1.8, 1994/05/07 03:03:13
Line 35 
Line 35 
  */   */
   
 #if defined(LIBC_SCCS) && !defined(lint)  #if defined(LIBC_SCCS) && !defined(lint)
 /* static char sccsid[] = "from: @(#)popen.c    8.1 (Berkeley) 6/4/93"; */  static char sccsid[] = "@(#)popen.c     8.1 (Berkeley) 6/4/93";
 static char *rcsid = "$Id$";  
 #endif /* LIBC_SCCS and not lint */  #endif /* LIBC_SCCS and not lint */
   
 #include <sys/param.h>  #include <sys/param.h>
Line 57  static struct pid {
Line 56  static struct pid {
 } *pidlist;  } *pidlist;
   
 FILE *  FILE *
 popen(command, type)  popen(program, type)
         const char *command;          const char *program;
         const char *type;          const char *type;
 {  {
         struct pid *cur;          struct pid *cur;
         FILE *iop;          FILE *iop;
         int pdes[2], pid;          int pdes[2], pid;
   
         if (*type != 'r' && *type != 'w' || type[1]) {          if (*type != 'r' && *type != 'w' || type[1])
                 errno = EINVAL;  
                 return (NULL);                  return (NULL);
         }  
   
         if ((cur = malloc(sizeof(struct pid))) == NULL)          if ((cur = malloc(sizeof(struct pid))) == NULL)
                 return (NULL);                  return (NULL);
Line 99  popen(command, type)
Line 96  popen(command, type)
                         }                          }
                         (void)close(pdes[1]);                          (void)close(pdes[1]);
                 }                  }
                 execl(_PATH_BSHELL, "sh", "-c", command, (char *) 0);                  execl(_PATH_BSHELL, "sh", "-c", program, NULL);
                 _exit(127);                  _exit(127);
                 /* NOTREACHED */                  /* NOTREACHED */
         }          }
Line 133  pclose(iop)
Line 130  pclose(iop)
 {  {
         register struct pid *cur, *last;          register struct pid *cur, *last;
         int omask;          int omask;
         int pstat;          union wait pstat;
         pid_t pid;          pid_t pid;
   
           (void)fclose(iop);
   
         /* Find the appropriate file pointer. */          /* Find the appropriate file pointer. */
         for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next)          for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next)
                 if (cur->fp == iop)                  if (cur->fp == iop)
Line 143  pclose(iop)
Line 142  pclose(iop)
         if (cur == NULL)          if (cur == NULL)
                 return (-1);                  return (-1);
   
         (void)fclose(iop);          /* Get the status of the process. */
           omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
         do {          do {
                 pid = waitpid(cur->pid, &pstat, 0);                  pid = waitpid(cur->pid, (int *) &pstat, 0);
         } while (pid == -1 && errno == EINTR);          } while (pid == -1 && errno == EINTR);
           (void)sigsetmask(omask);
   
         /* Remove the entry from the linked list. */          /* Remove the entry from the linked list. */
         if (last == NULL)          if (last == NULL)
Line 156  pclose(iop)
Line 156  pclose(iop)
                 last->next = cur->next;                  last->next = cur->next;
         free(cur);          free(cur);
   
         return (pid == -1 ? -1 : pstat);          return (pid == -1 ? -1 : pstat.w_status);
 }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

CVSweb <webmaster@jp.NetBSD.org>