[PATCH] Allow binary/text type in popen()

Christopher Faylor cgf@redhat.com
Sun Aug 4 12:02:00 GMT 2002

A user in the cygwin mailing list noted a problem with popen in that it
doesn't accept the 'b' or 't' qualifiers in the type argument.  newlib's
__sflags() allows the 'b' option regardless of target and the 't' option
under cygwin so it seems like popen() should accept something similar.

However, SuSv3 says that only "r" and "w" are correct arguments for
popen.  I don't see why popen should be different than fopen but I have
checked in the below cygwin-only change which is compliant with this

If the consensus is that popen should unconditionally accept the 'b'
option as fopen currently does, then I'll be happy to make that change.


2002-08-04  Christopher Faylor  <cgf@redhat.com>

	* libc/stdio/popen.c (popen): Allow "rb", "rt", "wb", and "wt"
	arguments for popen to match similar functionality in fopen.

Index: libc/posix/popen.c
RCS file: /cvs/uberbaum/newlib/libc/posix/popen.c,v
retrieving revision 1.3
diff -u -p -r1.3 popen.c
--- libc/posix/popen.c	22 Oct 2001 16:40:26 -0000	1.3
+++ libc/posix/popen.c	4 Aug 2002 19:00:40 -0000
@@ -71,7 +71,12 @@ popen(program, type)
 	FILE *iop;
 	int pdes[2], pid;
-       if ((*type != 'r' && *type != 'w') || type[1]) {
+       if ((*type != 'r' && *type != 'w')
+	   || (type[1]
+#ifdef __CYGWIN__
+	       && (type[2] || (type[1] != 'b' && type[1] != 't'))
+			       )) {
 		errno = EINVAL;
 		return (NULL);

More information about the Newlib mailing list