-
-
-int
-writeBase64aux (FILE *in, FILE *out)
-{
- unsigned int cc, n;
- char inbuf[3];
-
- n = BPERLIN;
- while ((cc = fread (inbuf, sizeof(*inbuf), sizeof(inbuf), in)) > 0) {
- unsigned long bits;
- char *bp;
- char outbuf[4];
-
- if (cc < sizeof(inbuf)) {
- inbuf[2] = 0;
- if (cc < sizeof(inbuf) - 1)
- inbuf[1] = 0;
- }
- bits = (inbuf[0] & 0xff) << 16;
- bits |= (inbuf[1] & 0xff) << 8;
- bits |= inbuf[2] & 0xff;
-
- for (bp = outbuf + sizeof(outbuf); bp > outbuf; bits >>= 6)
- *--bp = nib2b64[bits & 0x3f];
- if (cc < sizeof(inbuf)) {
- outbuf[3] = '=';
- if (cc < sizeof inbuf - 1)
- outbuf[2] = '=';
- }
-
- fwrite (outbuf, sizeof(*outbuf), sizeof(outbuf), out);
-
- if (cc < sizeof(inbuf)) {
- putc ('\n', out);
- return OK;
- }
-
- if (--n <= 0) {
- n = BPERLIN;
- putc ('\n', out);
- }
- }
- if (n != BPERLIN)
- putc ('\n', out);
-
- return OK;
-}