Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157269257
D36293.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D36293.diff
View Options
Index: usr.bin/bintrans/bintrans.1
===================================================================
--- usr.bin/bintrans/bintrans.1
+++ usr.bin/bintrans/bintrans.1
@@ -69,6 +69,7 @@
.Op Ar file
.Nm base64
.Op Fl d
+.Op Fl i | Fl n
.Op Fl w Ar column
.Op Ar file
.Sh DESCRIPTION
@@ -109,18 +110,6 @@
reads standard input or
.Ar file
if it is provided and writes to standard output.
-Options
-.Fl -wrap
-.Po or
-.Fl w
-.Pc
-and
-.Fl -ignore-garbage
-.Po or
-.Fl i
-.Pc
-are accepted for compatibility with GNU base64,
-but the latter is unimplemented and silently ignored.
.Pp
The
.Nm uuencode
@@ -215,11 +204,22 @@
.Pp
Additionally,
.Nm b64encode
-accepts the following option:
+and
+.Nm base64
+accept:
.Bl -tag -width ident
.It Fl w Ar column
-Wrap encoded output after
-.Ar column .
+to wrap encoded output after
+.Ar column
+.El
+.Pp
+and
+.Nm base64
+.Fl d
+accepts:
+.Bl -tag -width ident
+.It Fl i or Fl n
+to ignore non-alphabet charaters and suppress error checking.
.El
.Pp
.Nm
Index: usr.bin/bintrans/bintrans.c
===================================================================
--- usr.bin/bintrans/bintrans.c
+++ usr.bin/bintrans/bintrans.c
@@ -36,7 +36,7 @@
extern int main_decode(int, char *[]);
extern int main_encode(int, char *[]);
-extern int main_base64_decode(const char *);
+extern int main_base64_decode(const char *, bool);
extern int main_base64_encode(const char *, const char *);
extern int main_quotedprintable(int, char*[]);
@@ -108,7 +108,7 @@
static void
usage_base64(bool failure)
{
- (void)fputs("usage: base64 [-w col | --wrap=col] "
+ (void)fputs("usage: base64 [-w col | --wrap=col] [-i | -n] "
"[-d | --decode] [FILE]\n"
" base64 --help\n"
" base64 --version\n", stderr);
@@ -127,6 +127,7 @@
{
int ch;
bool decode = false;
+ bool ignore = false;
const char *w = NULL;
enum { HELP, VERSION };
static const struct option opts[] =
@@ -139,7 +140,7 @@
{NULL, no_argument, NULL, 0}
};
- while ((ch = getopt_long(argc, argv, "diw:", opts, NULL)) != -1)
+ while ((ch = getopt_long(argc, argv, "dinw:", opts, NULL)) != -1)
switch (ch) {
case 'd':
decode = true;
@@ -148,7 +149,8 @@
w = optarg;
break;
case 'i':
- /* silently ignore */
+ case 'n':
+ ignore = true;
break;
case VERSION:
version_base64();
@@ -159,7 +161,7 @@
}
if (decode)
- main_base64_decode(argv[optind]);
+ main_base64_decode(argv[optind], ignore);
else
main_base64_encode(argv[optind], w);
}
Index: usr.bin/bintrans/uudecode.c
===================================================================
--- usr.bin/bintrans/uudecode.c
+++ usr.bin/bintrans/uudecode.c
@@ -69,11 +69,11 @@
#include <unistd.h>
extern int main_decode(int, char *[]);
-extern int main_base64_decode(const char *);
+extern int main_base64_decode(const char *, bool);
static const char *infile, *outfile;
static FILE *infp, *outfp;
-static bool base64, cflag, iflag, oflag, pflag, rflag, sflag;
+static bool base64, cflag, iflag, oflag, pflag, rflag, sflag, nflag;
static void usage(void);
static int decode(void);
@@ -82,10 +82,11 @@
static int base64_decode(void);
int
-main_base64_decode(const char *in)
+main_base64_decode(const char *in, bool ignore)
{
base64 = 1;
rflag = 1;
+ nflag = ignore;
if (in != NULL) {
infile = in;
infp = fopen(infile, "r");
@@ -435,7 +436,7 @@
{
int n, count, count4;
char inbuf[MAXPATHLEN + 1], *p;
- unsigned char outbuf[MAXPATHLEN * 4];
+ unsigned char outbuf[MAXPATHLEN * 4], *o;
char leftover[MAXPATHLEN + 1];
leftover[0] = '\0';
@@ -451,29 +452,30 @@
count = 0;
count4 = -1;
- p = inbuf;
- while (*p != '\0') {
+ for (p = inbuf; *p != '\0'; p++) {
/*
* Base64 encoded strings have the following
* characters in them: A-Z, a-z, 0-9 and +, / and =
*/
if (isalnum(*p) || *p == '+' || *p == '/' || *p == '=')
count++;
+ else if (nflag)
+ *p = ' ';
if (count % 4 == 0)
count4 = p - inbuf;
- p++;
}
strcpy(leftover, inbuf + count4 + 1);
inbuf[count4 + 1] = 0;
- n = b64_pton(inbuf, outbuf, sizeof(outbuf));
+ o = outbuf;
+ n = b64_pton_partial(inbuf, &o, sizeof(outbuf));
- if (n < 0)
+ fwrite(outbuf, 1, o - outbuf, outfp);
+ if (!nflag && n < 0)
break;
- fwrite(outbuf, 1, n, outfp);
}
- return (checkend(inbuf, "====", "error decoding base64 input stream"));
+ return (!nflag && checkend(inbuf, "====", "error decoding base64 input stream"));
}
static void
Index: usr.bin/bintrans/uuencode.c
===================================================================
--- usr.bin/bintrans/uuencode.c
+++ usr.bin/bintrans/uuencode.c
@@ -284,6 +284,6 @@
{
(void)fprintf(stderr,
"usage: uuencode [-m] [-o outfile] [infile] remotefile\n"
-" b64encode [-o outfile] [infile] remotefile\n");
+" b64encode [-w column] [-o outfile] [infile] remotefile\n");
exit(1);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, May 20, 9:46 PM (13 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33358153
Default Alt Text
D36293.diff (4 KB)
Attached To
Mode
D36293: base64: implement -i/-n to ignore non-alphabet characters
Attached
Detach File
Event Timeline
Log In to Comment