summaryrefslogtreecommitdiff
path: root/other/openssh-2.1.1p4/uuencode.c
diff options
context:
space:
mode:
Diffstat (limited to 'other/openssh-2.1.1p4/uuencode.c')
-rw-r--r--other/openssh-2.1.1p4/uuencode.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/other/openssh-2.1.1p4/uuencode.c b/other/openssh-2.1.1p4/uuencode.c
new file mode 100644
index 0000000..27ba655
--- /dev/null
+++ b/other/openssh-2.1.1p4/uuencode.c
@@ -0,0 +1,50 @@
1/*
2 * Copyright (c) 2000 Markus Friedl. All rights reserved.
3 */
4#include "includes.h"
5#include "xmalloc.h"
6
7RCSID("$OpenBSD: uuencode.c,v 1.6 2000/06/22 23:55:00 djm Exp $");
8
9int
10uuencode(unsigned char *src, unsigned int srclength,
11 char *target, size_t targsize)
12{
13 return __b64_ntop(src, srclength, target, targsize);
14}
15
16int
17uudecode(const char *src, unsigned char *target, size_t targsize)
18{
19 int len;
20 char *encoded, *p;
21
22 /* copy the 'readonly' source */
23 encoded = xstrdup(src);
24 /* skip whitespace and data */
25 for (p = encoded; *p == ' ' || *p == '\t'; p++)
26 ;
27 for (; *p != '\0' && *p != ' ' && *p != '\t'; p++)
28 ;
29 /* and remote trailing whitespace because __b64_pton needs this */
30 *p = '\0';
31 len = __b64_pton(encoded, target, targsize);
32 xfree(encoded);
33 return len;
34}
35
36void
37dump_base64(FILE *fp, unsigned char *data, int len)
38{
39 unsigned char *buf = xmalloc(2*len);
40 int i, n;
41 n = uuencode(data, len, buf, 2*len);
42 for (i = 0; i < n; i++) {
43 fprintf(fp, "%c", buf[i]);
44 if (i % 70 == 69)
45 fprintf(fp, "\n");
46 }
47 if (i % 70 != 69)
48 fprintf(fp, "\n");
49 xfree(buf);
50}