]> andersk Git - openssh.git/blob - uuencode.c
- OpenBSD CVS Updates:
[openssh.git] / uuencode.c
1 /*
2  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
3  */
4 #include "includes.h"
5 #include "xmalloc.h"
6
7 RCSID("$OpenBSD: uuencode.c,v 1.6 2000/06/22 23:55:00 djm Exp $");
8
9 int
10 uuencode(unsigned char *src, unsigned int srclength,
11     char *target, size_t targsize)
12 {
13         return __b64_ntop(src, srclength, target, targsize);
14 }
15
16 int
17 uudecode(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
36 void
37 dump_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 }
This page took 0.048938 seconds and 5 git commands to generate.