xref: /freebsd/lib/libc/stdlib/a64l.3 (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1.\" Copyright (c) 2005 Tom Rhodes
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" Portions of this text are reprinted and reproduced in electronic form
26.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
27.\" Portable Operating System Interface (POSIX), The Open Group Base
28.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
29.\" Electrical and Electronics Engineers, Inc and The Open Group.  In the
30.\" event of any discrepancy between this version and the original IEEE and
31.\" The Open Group Standard, the original IEEE and The Open Group Standard is
32.\" the referee document.  The original Standard can be obtained online at
33.\"	http://www.opengroup.org/unix/online.html.
34.\"
35.Dd November 20, 2005
36.Dt A64L 3
37.Os
38.Sh NAME
39.Nm a64l ,
40.Nm l64a ,
41.Nm l64a_r
42.Nd "convert between a long integer and a base-64 ASCII string"
43.Sh LIBRARY
44.Lb libc
45.Sh SYNOPSIS
46.In stdlib.h
47.Ft long
48.Fn a64l "const char *s"
49.Ft char *
50.Fn l64a "long int l"
51.Ft int
52.Fn l64a_r "long int l" "char *buffer" "int buflen"
53.Sh DESCRIPTION
54These functions are used to maintain numbers stored in radix-64
55.Tn ASCII
56characters.
57This is a notation by which 32-bit integers can be represented by
58up to six characters; each character represents a digit in
59radix-64 notation.
60If the type long contains more than 32 bits, only the low-order
6132 bits are used for these operations.
62.Pp
63The characters used to represent
64.Dq digits
65are
66.Ql .\&
67for 0,
68.Ql /
69for 1,
70.Ql 0
71-
72.Ql 9
73for 2 - 11,
74.Ql A
75-
76.Ql Z
77for 12 - 37, and
78.Ql a
79-
80.Ql z
81for 38 - 63.
82.Pp
83The
84.Fn a64l
85function takes a pointer to a radix-64 representation, in which the first
86digit is the least significant, and returns a corresponding
87.Vt long
88value.
89If the string pointed to by
90.Fa s
91contains more than six characters,
92.Fn a64l
93uses the first six.
94If the first six characters of the string contain a null terminator,
95.Fn a64l
96uses only characters preceding the null terminator.
97The
98.Fn a64l
99function scans the character string from left to right with the least
100significant digit on the left, decoding each character as a 6-bit
101radix-64 number.
102If the type long contains more than 32 bits, the resulting value is
103sign-extended.
104The behavior of
105.Fn a64l
106is unspecified if
107.Fa s
108is a null pointer or the string pointed to by
109.Fa s
110was not generated by a previous call to
111.Fn l64a .
112.Pp
113The
114.Fn l64a
115function takes a
116.Vt long
117argument and returns a pointer to the corresponding
118radix-64 representation.
119The behavior of
120.Fn l64a
121is unspecified if value is negative.
122.Pp
123The value returned by
124.Fn l64a
125is a pointer into a static buffer.
126Subsequent calls to
127.Fn l64a
128may overwrite the buffer.
129.Pp
130The
131.Fn l64a_r
132function performs a conversion identical to that of
133.Fn l64a
134and stores the resulting representation in the memory area pointed to by
135.Fa buffer ,
136consuming at most
137.Fa buflen
138characters including the terminating
139.Dv NUL
140character.
141.Sh RETURN VALUES
142On successful completion,
143.Fn a64l
144returns the
145.Vt long
146value resulting from conversion of the input string.
147If a string pointed to by
148.Fa s
149is an empty string,
150.Fn a64l
151returns 0.
152.Pp
153The
154.Fn l64a
155function returns a pointer to the radix-64 representation.
156If value is 0,
157.Fn l64a
158returns a pointer to an empty string.
159.Sh SEE ALSO
160.Xr strtoul 3
161.Sh HISTORY
162The
163.Fn a64l ,
164.Fn l64a ,
165and
166.Fn l64a_r
167functions are derived from
168.Nx
169with modifications.
170They appeared in
171.Fx 6.1 .
172.Sh AUTHORS
173The
174.Fn a64l ,
175.Fn l64a ,
176and
177.Fn l64a_r
178functions
179were added to
180.Fx
181by
182.An Tom Rhodes Aq Mt trhodes@FreeBSD.org .
183Almost all of this manual page came from the
184.Tn POSIX
185standard.
186