summaryrefslogtreecommitdiff
path: root/radix.c
diff options
context:
space:
mode:
Diffstat (limited to 'radix.c')
-rw-r--r--radix.c96
1 files changed, 1 insertions, 95 deletions
diff --git a/radix.c b/radix.c
index 84e390fd1..9d1c999a1 100644
--- a/radix.c
+++ b/radix.c
@@ -1,109 +1,15 @@
1/* 1/*
2 * radix.c 2 * radix.c
3 * 3 *
4 * base-64 encoding pinched from lynx2-7-2, who pinched it from rpem.
5 * Originally written by Mark Riordan 12 August 1990 and 17 Feb 1991
6 * and placed in the public domain.
7 *
8 * Dug Song <dugsong@UMICH.EDU> 4 * Dug Song <dugsong@UMICH.EDU>
9 */ 5 */
10 6
11#include "includes.h" 7#include "includes.h"
8#include "uuencode.h"
12 9
13#ifdef AFS 10#ifdef AFS
14#include <krb.h> 11#include <krb.h>
15 12
16char six2pr[64] = {
17 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
18 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
19 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
20 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
21 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
22};
23
24unsigned char pr2six[256];
25
26int
27uuencode(unsigned char *bufin, unsigned int nbytes, char *bufcoded)
28{
29 /* ENC is the basic 1 character encoding function to make a char printing */
30#define ENC(c) six2pr[c]
31
32 register char *outptr = bufcoded;
33 unsigned int i;
34
35 for (i = 0; i < nbytes; i += 3) {
36 *(outptr++) = ENC(*bufin >> 2); /* c1 */
37 *(outptr++) = ENC(((*bufin << 4) & 060) | ((bufin[1] >> 4) & 017)); /* c2 */
38 *(outptr++) = ENC(((bufin[1] << 2) & 074) | ((bufin[2] >> 6) & 03)); /* c3 */
39 *(outptr++) = ENC(bufin[2] & 077); /* c4 */
40 bufin += 3;
41 }
42 if (i == nbytes + 1) {
43 outptr[-1] = '=';
44 } else if (i == nbytes + 2) {
45 outptr[-1] = '=';
46 outptr[-2] = '=';
47 }
48 *outptr = '\0';
49 return (outptr - bufcoded);
50}
51
52int
53uudecode(const char *bufcoded, unsigned char *bufplain, int outbufsize)
54{
55 /* single character decode */
56#define DEC(c) pr2six[(unsigned char)c]
57#define MAXVAL 63
58
59 static int first = 1;
60 int nbytesdecoded, j;
61 const char *bufin = bufcoded;
62 register unsigned char *bufout = bufplain;
63 register int nprbytes;
64
65 /* If this is the first call, initialize the mapping table. */
66 if (first) {
67 first = 0;
68 for (j = 0; j < 256; j++)
69 pr2six[j] = MAXVAL + 1;
70 for (j = 0; j < 64; j++)
71 pr2six[(unsigned char) six2pr[j]] = (unsigned char) j;
72 }
73 /* Strip leading whitespace. */
74 while (*bufcoded == ' ' || *bufcoded == '\t')
75 bufcoded++;
76
77 /*
78 * Figure out how many characters are in the input buffer. If this
79 * would decode into more bytes than would fit into the output
80 * buffer, adjust the number of input bytes downwards.
81 */
82 bufin = bufcoded;
83 while (DEC(*(bufin++)) <= MAXVAL);
84 nprbytes = bufin - bufcoded - 1;
85 nbytesdecoded = ((nprbytes + 3) / 4) * 3;
86 if (nbytesdecoded > outbufsize)
87 nprbytes = (outbufsize * 4) / 3;
88
89 bufin = bufcoded;
90
91 while (nprbytes > 0) {
92 *(bufout++) = (unsigned char) (DEC(*bufin) << 2 | DEC(bufin[1]) >> 4);
93 *(bufout++) = (unsigned char) (DEC(bufin[1]) << 4 | DEC(bufin[2]) >> 2);
94 *(bufout++) = (unsigned char) (DEC(bufin[2]) << 6 | DEC(bufin[3]));
95 bufin += 4;
96 nprbytes -= 4;
97 }
98 if (nprbytes & 03) {
99 if (DEC(bufin[-2]) > MAXVAL)
100 nbytesdecoded -= 2;
101 else
102 nbytesdecoded -= 1;
103 }
104 return (nbytesdecoded);
105}
106
107typedef unsigned char my_u_char; 13typedef unsigned char my_u_char;
108typedef unsigned int my_u_int32_t; 14typedef unsigned int my_u_int32_t;
109typedef unsigned short my_u_short; 15typedef unsigned short my_u_short;