[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.1.1.3 and 1.17

version 1.1.1.3, 1998/02/02 00:11:32 version 1.17, 1998/02/02 02:54:28
Line 1 
Line 1 
   /*      $NetBSD$        */
   
 /*  /*
  * Copyright (c) 1988, 1993   * Copyright (c) 1988, 1993
  *      The Regents of the University of California.  All rights reserved.   *      The Regents of the University of California.  All rights reserved.
Line 34 
Line 36 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
   #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)  #if defined(LIBC_SCCS) && !defined(lint)
   #if 0
 static char sccsid[] = "@(#)popen.c     8.3 (Berkeley) 5/3/95";  static char sccsid[] = "@(#)popen.c     8.3 (Berkeley) 5/3/95";
   #else
   __RCSID("$NetBSD$");
   #endif
 #endif /* LIBC_SCCS and not lint */  #endif /* LIBC_SCCS and not lint */
   
   #include "namespace.h"
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/wait.h>  #include <sys/wait.h>
 #include <sys/socket.h>  #include <sys/socket.h>
Line 50  static char sccsid[] = "@(#)popen.c 8.3 
Line 58  static char sccsid[] = "@(#)popen.c 8.3 
 #include <string.h>  #include <string.h>
 #include <paths.h>  #include <paths.h>
   
   #ifdef __weak_alias
   __weak_alias(popen,_popen);
   __weak_alias(pclose,_pclose);
   #endif
   
 static struct pid {  static struct pid {
         struct pid *next;          struct pid *next;
         FILE *fp;          FILE *fp;
Line 60  FILE *
Line 73  FILE *
 popen(command, type)  popen(command, type)
         const char *command, *type;          const char *command, *type;
 {  {
         struct pid *cur;          struct pid *cur, *old;
         FILE *iop;          FILE *iop;
         int pdes[2], pid, twoway;          int pdes[2], pid, twoway;
   #ifdef __GNUC__
           (void) &cur;
   #endif
   
         if (strchr(type, '+')) {          if (strchr(type, '+')) {
                 twoway = 1;                  twoway = 1;
Line 72  popen(command, type)
Line 88  popen(command, type)
         } else  {          } else  {
                 twoway = 0;                  twoway = 0;
                 if (*type != 'r' && *type != 'w' || type[1] ||                  if (*type != 'r' && *type != 'w' || type[1] ||
                     (pipe(pdes) < 0))                      (pipe(pdes) < 0)) {
                           errno = EINVAL;
                         return (NULL);                          return (NULL);
                   }
         }          }
   
         if ((cur = malloc(sizeof(struct pid))) == NULL)          if ((cur = malloc(sizeof(struct pid))) == NULL)
Line 83  popen(command, type)
Line 101  popen(command, type)
         case -1:                        /* Error. */          case -1:                        /* Error. */
                 (void)close(pdes[0]);                  (void)close(pdes[0]);
                 (void)close(pdes[1]);                  (void)close(pdes[1]);
                 (void)free(cur);                  free(cur);
                 return (NULL);                  return (NULL);
                 /* NOTREACHED */                  /* NOTREACHED */
         case 0:                         /* Child. */          case 0:                         /* Child. */
Line 103  popen(command, type)
Line 121  popen(command, type)
                         }                          }
                         (void)close(pdes[1]);                          (void)close(pdes[1]);
                 }                  }
   
                   /* POSIX.2 B.3.2.2 "popen() shall ensure that any streams
                      from previous popen() calls that remain open in the
                      parent process are closed in the new child process. */
                   for (old = pidlist; old; old = old->next)
                           close(fileno(old->fp));
   
                 execl(_PATH_BSHELL, "sh", "-c", command, NULL);                  execl(_PATH_BSHELL, "sh", "-c", command, NULL);
                 _exit(127);                  _exit(127);
                 /* NOTREACHED */                  /* NOTREACHED */
Line 136  pclose(iop)
Line 161  pclose(iop)
         FILE *iop;          FILE *iop;
 {  {
         register struct pid *cur, *last;          register struct pid *cur, *last;
         int omask;  
         int pstat;          int pstat;
         pid_t pid;          pid_t pid;
   

Legend:
Removed from v.1.1.1.3  
changed lines
  Added in v.1.17

CVSweb <webmaster@jp.NetBSD.org>