Subject: bin/7183: set output to stdout for uudecode
To: None <gnats-bugs@gnats.netbsd.org>
From: SUNAGAWA Keiki <Keiki_SUNAGAWA@yokogawa.co.jp>
List: netbsd-bugs
Date: 03/18/1999 11:10:21
>Number:         7183
>Category:       bin
>Synopsis:       set output to stdout for uudecode
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 17 18:20:01 1999
>Last-Modified:
>Originator:     SUNAGAWA Keiki
>Organization:
	Yokogawa Electric Corporation
>Release:        1.3.3
>Environment:
System: NetBSD vivid 1.3.3 NetBSD 1.3.3 (VIVID) #1: Wed Feb 10 18:45:16 JST 1999 kei@vivid:/var/src/sys/arch/i386/compile/VIVID i386


>Description:
	uudecode output cannot be redirected.  It is convenient if it can,
	especially when the encoded file is a patch.
>How-To-Repeat:
	prepare an uuencodeed file, chdir to the place where you have no write
	permission, and uudecode the file.
>Fix:
	Apply the following patch.

	To set the output to stdout, use the '-p' option.


--- uudecode.c.orig	Wed Mar 17 17:30:44 1999
+++ uudecode.c	Wed Mar 17 17:51:42 1999
@@ -66,6 +66,7 @@
 static void usage __P((void));
 int main __P((int, char **));
 
+int pflag = 0;
 char *filename;
 
 int
@@ -73,12 +74,18 @@
 	int argc;
 	char *argv[];
 {
-	int rval;
+	int ch, rval;
 
 	setlocale(LC_ALL, "");
 
-	while (getopt(argc, argv, "") != -1)
-		usage();
+	while ((ch = getopt(argc, argv, "p")) != -1)
+		switch((char)ch) {
+		case 'p':
+			pflag = 1;
+			break;
+		default:
+			usage();
+		}
 	argc -= optind;
 	argv += optind;
 
@@ -141,8 +148,8 @@
 	}
 
 	/* create output file, set mode */
-	if (!freopen(buf, "w", stdout) ||
-	    fchmod(fileno(stdout), mode&0666)) {
+	if ((!pflag) && (!freopen(buf, "w", stdout) ||
+	    fchmod(fileno(stdout), mode&0666))) {
 		warnx("%s: %s", buf, filename);
 		return(1);
 	}
>Audit-Trail:
>Unformatted: