blob: fde8296c8499b33613b05fa580a59f426820db32 [file] [log] [blame]
rsccfa37a72004-04-10 18:53:55 +00001.TH ENCODE 3
2.SH NAME
3dec64, enc64, dec32, enc32, dec16, enc16, encodefmt \- encoding byte arrays as strings
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.PP
9.B
10int dec64(uchar *out, int lim, char *in, int n)
11.PP
12.B
13int enc64(char *out, int lim, uchar *in, int n)
14.PP
15.B
16int dec32(uchar *out, int lim, char *in, int n)
17.PP
18.B
19int enc32(char *out, int lim, uchar *in, int n)
20.PP
21.B
22int dec16(uchar *out, int lim, char *in, int n)
23.PP
24.B
25int enc16(char *out, int lim, uchar *in, int n)
26.PP
27.B
28int encodefmt(Fmt*)
29.SH DESCRIPTION
30.PP
31.IR Enc16 ,
32.I enc32
33and
34.I enc64
35create null terminated strings. They return the size of the
36encoded string (without the null) or -1 if the encoding fails.
37The encoding fails if
38.IR lim ,
39the length of the output buffer, is too small.
40.PP
41.IR Dec16 ,
42.I dec32
43and
44.I dec64
45return the number of bytes decoded or -1 if the decoding fails.
46The decoding fails if the output buffer is not large enough or,
47for base 32, if the input buffer length is not a multiple
48of 8.
49.PP
50.I Encodefmt
51can be used with
rscbf8a59f2004-04-11 03:42:27 +000052.IR fmtinstall (3)
rsccfa37a72004-04-10 18:53:55 +000053and
rscbf8a59f2004-04-11 03:42:27 +000054.IR print (3)
rsccfa37a72004-04-10 18:53:55 +000055to print encoded representations of byte arrays.
56The verbs are
57.TP
58.B H
59base 16 (i.e. hexadecimal). The default encoding is
60in upper case. The
61.B l
62flag forces lower case.
63.TP
64.B <
65base 32
66.TP
67.B [
68base 64 (same as MIME)
69.PD
70.PP
71The length of the array is specified as
72.IR f2 .
73For example, to display a 15 byte array as hex:
74.EX
75
76 char x[15];
77
78 fmtinstall('H', encodefmt);
79 print("%.*H\\n", sizeof x, x);
80
81.EE
82.SH SOURCE
rscc3674de2005-01-11 17:37:33 +000083.B \*9/src/lib9/u32.c
rsccfa37a72004-04-10 18:53:55 +000084.br
rscc3674de2005-01-11 17:37:33 +000085.B \*9/src/lib9/u64.c