Loading...
--- Libc/Libc-391.5.21/gen/FreeBSD/popen.c.patch
+++ Libc/Libc-498/gen/FreeBSD/popen.c.patch
@@ -1,14 +1,16 @@
--- popen.c.orig 2003-05-20 15:21:02.000000000 -0700
-+++ popen.c 2005-09-17 16:08:55.000000000 -0700
-@@ -43,6 +43,7 @@
++++ popen.c 2005-09-14 15:53:35.000000000 -0700
+@@ -43,7 +43,8 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/pop
#include "namespace.h"
#include <sys/param.h>
#include <sys/wait.h>
+-
+#include <sys/socket.h>
-
++#include <wchar.h> /* fwide() */
#include <signal.h>
#include <errno.h>
-@@ -55,11 +56,14 @@
+ #include <unistd.h>
+@@ -55,11 +56,14 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/pop
#include "un-namespace.h"
#include "libc_private.h"
@@ -24,7 +26,7 @@
pid_t pid;
} *pidlist;
static pthread_mutex_t pidlist_mutex = PTHREAD_MUTEX_INITIALIZER;
-@@ -77,20 +81,18 @@
+@@ -77,20 +81,24 @@ popen(command, type)
char *argv[4];
struct pid *p;
@@ -32,24 +34,30 @@
- * Lite2 introduced two-way popen() pipes using _socketpair().
- * FreeBSD's pipe() is bidirectional, so we use that.
- */
- if (strchr(type, '+')) {
+- if (strchr(type, '+')) {
++ if (type == NULL) {
++ errno = EINVAL;
++ return (NULL);
++ }
++ if (strcmp(type, "r+") == 0) {
twoway = 1;
type = "r+";
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, pdes) < 0)
+ return (NULL);
} else {
twoway = 0;
- if ((*type != 'r' && *type != 'w') || type[1])
+- if ((*type != 'r' && *type != 'w') || type[1])
++ if ((*type != 'r' && *type != 'w') || type[1]) {
++ errno = EINVAL;
return (NULL);
-+ if (pipe(pdes) < 0)
-+ return (NULL);
}
-- if (pipe(pdes) < 0)
-- return (NULL);
+ if (pipe(pdes) < 0)
+ return (NULL);
++ }
if ((cur = malloc(sizeof(struct pid))) == NULL) {
(void)_close(pdes[0]);
-@@ -104,7 +106,7 @@
+@@ -104,7 +112,7 @@ popen(command, type)
argv[3] = NULL;
THREAD_LOCK();
@@ -58,7 +66,7 @@
case -1: /* Error. */
THREAD_UNLOCK();
(void)_close(pdes[0]);
-@@ -138,7 +140,7 @@
+@@ -138,7 +146,7 @@ popen(command, type)
(void)_close(pdes[1]);
}
for (p = pidlist; p; p = p->next) {
@@ -67,7 +75,7 @@
}
_execve(_PATH_BSHELL, argv, environ);
_exit(127);
-@@ -149,9 +151,11 @@
+@@ -149,9 +157,11 @@ popen(command, type)
/* Parent; assume fdopen can't fail. */
if (*type == 'r') {
iop = fdopen(pdes[0], type);
@@ -79,3 +87,12 @@
(void)_close(pdes[0]);
}
+@@ -162,7 +172,7 @@ popen(command, type)
+ cur->next = pidlist;
+ pidlist = cur;
+ THREAD_UNLOCK();
+-
++ fwide(iop, -1); /* byte stream */
+ return (iop);
+ }
+