Cc
Bcc: [EMAIL PROTECTED]
Subject:
Reply-To:
tags 324935 + patch
tags 324929 + patch
thanks
Hello,
the attached patch fixes the problem (it simply stopped reading the
output on the first = char, ie. on the first chunk though there were
multiple in the stream) and also adds buffering to make the thing four
times faster.
Eduard.
--
<mrvn> Jemand hier der buffy als DVD hat oder haben wird?
* mrvn outet sich mal als Buffy fan.
* weaselTM steht auf und setzt sich so weit wie moeglich von mrvn weg.
* nobse ist auch buffy fan :)
* nobse laeuft hinter weasel her
<weaselTM> was ist denn heutzutage alles maintainer. schrecklich. wir
haben kein nivea^Wlevel mehr
--- vm-7.19/base64-decode.c
+++ vm-7.19/base64-decode.c
@@ -21,7 +21,7 @@
main()
{
static char inalphabet[256], decoder[256];
- int i, bits, c, char_count, errors = 0;
+ int i, bits, char_count, errors = 0;
#ifdef WIN32
_setmode( _fileno(stdout), _O_BINARY);
@@ -34,43 +34,60 @@
- char_count = 0;
- bits = 0;
- while ((c = getchar()) != EOF) {
- if (c == '=')
- break;
- if (c > 255 || ! inalphabet[c])
- continue;
- bits += decoder[c];
- char_count++;
- if (char_count == 4) {
- putchar((bits >> 16));
- putchar(((bits >> 8) & 0xff));
- putchar((bits & 0xff));
- bits = 0;
- char_count = 0;
- } else {
- bits <<= 6;
- }
- }
- if (c == EOF) {
- if (char_count) {
- fprintf(stderr, "base64-decode: base64 encoding incomplete: at
least %d bits truncated",
- ((4 - char_count) * 6));
- errors++;
- }
- } else { /* c == '=' */
- switch (char_count) {
- case 1:
- fprintf(stderr, "base64-decode: base64 encoding incomplete: at
least 2 bits missing");
- errors++;
- break;
- case 2:
- putchar((bits >> 10));
- break;
- case 3:
- putchar((bits >> 16));
- putchar(((bits >> 8) & 0xff));
- break;
- }
+#define BUFLEN 72*500 // must be multiple of 4
+
+ int len;
+ char buf[BUFLEN];
+ char outbuf[BUFLEN];
+
+ while(!feof(stdin)) {
+ unsigned char c;
+
+ int pos=0;
+ char *out=outbuf;
+ len=fread(buf, sizeof(c), BUFLEN, stdin);
+ if(!len) continue;
+
+cont_buffer:
+ char_count = 0;
+ bits = 0;
+ while(pos<len) {
+ c=buf[pos++];
+ if (c == '=')
+ break;
+ if (! inalphabet[c])
+ continue;
+ bits += decoder[c];
+ char_count++;
+ if (char_count == 4) {
+ *out++ = ((bits >> 16));
+ *out++ = (((bits >> 8) & 0xff));
+ *out++ = ((bits & 0xff));
+ bits = 0;
+ char_count = 0;
+ } else {
+ bits <<= 6;
+ }
+ }
+ switch (char_count) {
+ case 1:
+ fprintf(stderr, "base64-decode: base64 encoding incomplete: at
least 2 bits missing");
+ errors++;
+ break;
+ case 2:
+ *out++ = ((bits >> 10));
+ break;
+ case 3:
+ *out++ = ((bits >> 16));
+ *out++ = (((bits >> 8) & 0xff));
+ break;
+ case 0:
+ break;
+ default:
+ fprintf(stderr, "base64-decode: base64 encoding incomplete: at
least %d bits truncated",
+ ((4 - char_count) * 6));
+ }
+ if(pos<len) // did not proceed the whole thing, continue
+ goto cont_buffer;
+ fwrite(outbuf, sizeof(char), (out-outbuf), stdout);
}
- exit(errors ? 1 : 0);
+ return (errors ? 1 : 0);
}