diff options
author | Sheldon Hearn <sheldonh@FreeBSD.org> | 2000-03-27 11:49:36 +0000 |
---|---|---|
committer | Sheldon Hearn <sheldonh@FreeBSD.org> | 2000-03-27 11:49:36 +0000 |
commit | a6eb0df2474c255c32b770ed16db04f0cfdd7ae0 (patch) | |
tree | e9aa8be20c6cb037abe924be51878039854eaa24 /usr.bin/uudecode | |
parent | a2554a04dbca431a7f5ce071402e1c7a17c1b810 (diff) | |
download | src-a6eb0df2474c255c32b770ed16db04f0cfdd7ae0.tar.gz src-a6eb0df2474c255c32b770ed16db04f0cfdd7ae0.zip |
Do not overwrite files when the -i option is specified!
PR: 17476
Reported by: Jonathan Chen <jon@spock.org>
Notes
Notes:
svn path=/head/; revision=58666
Diffstat (limited to 'usr.bin/uudecode')
-rw-r--r-- | usr.bin/uudecode/uudecode.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/usr.bin/uudecode/uudecode.c b/usr.bin/uudecode/uudecode.c index 247e80212d1e..1716c10e8dcd 100644 --- a/usr.bin/uudecode/uudecode.c +++ b/usr.bin/uudecode/uudecode.c @@ -141,11 +141,11 @@ decode2(flag) struct passwd *pw; register int n; register char ch, first, *p; - int mode, n1; + int ignore, mode, n1; char buf[MAXPATHLEN]; char buffn[MAXPATHLEN]; /* file name buffer */ - + ignore = 0; /* search for header line */ do { if (!fgets(buf, sizeof(buf), stdin)) { @@ -197,9 +197,10 @@ decode2(flag) ; /* print to stdout */ else { - if (iflag && !access(buf, F_OK)) + if (iflag && !access(buf, F_OK)) { (void)fprintf(stderr, "not overwritten: %s\n", buf); - if (!freopen(buf, "w", stdout) || + ignore++; + } else if (!freopen(buf, "w", stdout) || fchmod(fileno(stdout), mode&0666)) { warn("%s: %s", buf, filename); return(1); @@ -224,6 +225,9 @@ decode2(flag) filename, buffn, 1 + ' ', 077 + ' ' + 1); \ return(1); \ } +#define PUTCHAR(c) \ +if (!ignore) \ + putchar(c) /* @@ -239,11 +243,11 @@ decode2(flag) OUT_OF_RANGE ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4; - putchar(ch); + PUTCHAR(ch); ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2; - putchar(ch); + PUTCHAR(ch); ch = DEC(p[2]) << 6 | DEC(p[3]); - putchar(ch); + PUTCHAR(ch); } else { @@ -251,7 +255,7 @@ decode2(flag) if (!(IS_DEC(*p) && IS_DEC(*(p + 1)))) OUT_OF_RANGE ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4; - putchar(ch); + PUTCHAR(ch); } if (n >= 2) { if (!(IS_DEC(*(p + 1)) && @@ -259,14 +263,14 @@ decode2(flag) OUT_OF_RANGE ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2; - putchar(ch); + PUTCHAR(ch); } if (n >= 3) { if (!(IS_DEC(*(p + 2)) && IS_DEC(*(p + 3)))) OUT_OF_RANGE ch = DEC(p[2]) << 6 | DEC(p[3]); - putchar(ch); + PUTCHAR(ch); } } } |