summaryrefslogtreecommitdiffstats
path: root/usr.bin/uudecode/uudecode.c
diff options
context:
space:
mode:
authormike <mike@FreeBSD.org>2002-01-27 18:21:23 +0000
committermike <mike@FreeBSD.org>2002-01-27 18:21:23 +0000
commit7e26e18582964ec5bb216ce4d68c1ce441d375d8 (patch)
tree6ae7c1c1eee23b4c5f19270e93685c55f5766902 /usr.bin/uudecode/uudecode.c
parent9fdf88975bc0d2bd305b2bf4f93639a9e2dd2f3b (diff)
downloadFreeBSD-src-7e26e18582964ec5bb216ce4d68c1ce441d375d8.zip
FreeBSD-src-7e26e18582964ec5bb216ce4d68c1ce441d375d8.tar.gz
Add -o option (POSIX.1-2001) to uudecode(1). Deprecate the -p option
(which allows one to redirect output to stdout); `-o /dev/stdout' is recommended instead. Submitted by: Joseph Mallett <jmallett@xMach.org> MFC after: 2 weeks
Diffstat (limited to 'usr.bin/uudecode/uudecode.c')
-rw-r--r--usr.bin/uudecode/uudecode.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/usr.bin/uudecode/uudecode.c b/usr.bin/uudecode/uudecode.c
index 182bb8f..38e7ec5 100644
--- a/usr.bin/uudecode/uudecode.c
+++ b/usr.bin/uudecode/uudecode.c
@@ -63,7 +63,8 @@ static const char rcsid[] =
#include <unistd.h>
const char *filename;
-int cflag, iflag, pflag, sflag;
+char *outfile;
+int cflag, iflag, oflag, pflag, sflag;
static void usage __P((void));
int decode __P((void));
@@ -76,18 +77,32 @@ main(argc, argv)
{
int rval, ch;
- while ((ch = getopt(argc, argv, "cips")) != -1) {
+ while ((ch = getopt(argc, argv, "cio:ps")) != -1) {
switch(ch) {
case 'c':
+ if (oflag)
+ usage();
cflag = 1; /* multiple uudecode'd files */
break;
case 'i':
iflag = 1; /* ask before override files */
break;
+ case 'o':
+ if (cflag || pflag || sflag)
+ usage();
+ oflag = 1; /* output to the specified file */
+ sflag = 1; /* do not strip pathnames for output */
+ outfile = optarg; /* set the output filename */
+ break;
case 'p':
+ if (oflag)
+ usage();
+ warnx("-p is deprecated, use `-o /dev/stdout' instead.");
pflag = 1; /* print output to stdout */
break;
case 's':
+ if (oflag)
+ usage();
sflag = 1; /* do not strip pathnames for output */
break;
default:
@@ -158,7 +173,14 @@ decode2(flag)
} while (strncmp(buf, "begin ", 6) ||
fnmatch("begin [0-7]* *", buf, 0));
- (void)sscanf(buf, "begin %o %[^\n\r]", &mode, buf);
+ if (oflag) {
+ (void)sscanf(buf, "begin %o ", &mode);
+ if (strlcpy(buf, outfile, sizeof(buf)) >= sizeof(buf)) {
+ warnx("%s: filename too long", outfile);
+ return (1);
+ }
+ } else
+ (void)sscanf(buf, "begin %o %[^\n\r]", &mode, buf);
if (!sflag && !pflag) {
strncpy(buffn, buf, sizeof(buffn));
@@ -287,5 +309,6 @@ static void
usage()
{
(void)fprintf(stderr, "usage: uudecode [-cips] [file ...]\n");
+ (void)fprintf(stderr, "usage: uudecode [-i] -o output_file [file]\n");
exit(1);
}
OpenPOWER on IntegriCloud