summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormillert <>1997-08-17 22:58:34 +0000
committermillert <>1997-08-17 22:58:34 +0000
commit8a261abefde3eb7c4a3ecb94acbb4b500b8cd1aa (patch)
tree212dd7f0f17b38e109915044266255b50045cbfd /src
parentcba49e2afc06b0931ffbc483c4bb576c342c3384 (diff)
downloadopenbsd-8a261abefde3eb7c4a3ecb94acbb4b500b8cd1aa.tar.gz
openbsd-8a261abefde3eb7c4a3ecb94acbb4b500b8cd1aa.tar.bz2
openbsd-8a261abefde3eb7c4a3ecb94acbb4b500b8cd1aa.zip
Man page for a64l(3) and l64a(3), based on a64l.3 from the MiNT docs 0.1.
Also make a64l(3) and l64a(3) deal reasonably with inapropriate input. The standard does not require this, but it does not disallow it either.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/a64l.3125
-rw-r--r--src/lib/libc/stdlib/a64l.c26
-rw-r--r--src/lib/libc/stdlib/l64a.c13
3 files changed, 152 insertions, 12 deletions
diff --git a/src/lib/libc/stdlib/a64l.3 b/src/lib/libc/stdlib/a64l.3
new file mode 100644
index 0000000000..5093edb51f
--- /dev/null
+++ b/src/lib/libc/stdlib/a64l.3
@@ -0,0 +1,125 @@
1.\"
2.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\" notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\" notice, this list of conditions and the following disclaimer in the
12.\" documentation and/or other materials provided with the distribution.
13.\" 3. All advertising materials mentioning features or use of this software
14.\" must display the following acknowledgement:
15.\" This product includes software developed by Todd C. Miller.
16.\" 4. The name of the author may not be used to endorse or promote products
17.\" derived from this software without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29.\"
30.\" $OpenBSD: a64l.3,v 1.1 1997/08/17 22:58:33 millert Exp $
31.\"
32.Dd August 17, 1997
33.Dt A64L 3
34.Os
35.Sh NAME
36.Nm a64l ,
37.Nm l64a
38.Nd convert between 32-bit integer and radix-64 ASCII string
39.Sh SYNOPSIS
40.Fd #include <stdlib.h>
41.Ft long
42.Fn a64l "const char *s"
43.Ft char *
44.Fn l64a "long l"
45.Sh DESCRIPTION
46The
47.Fn a64l
48and
49.Fn l64a
50functions are used to maintain numbers stored in radix-64
51ASCII characters. This is a notation by which 32-bit integers
52can be represented by up to six characters; each character
53represents a "digit" in a radix-64 notation.
54.Pp
55The characters used to represent "digits" are '.' for 0, '/' for 1,
56'0' through '9' for 2-11, 'A' through 'Z' for 12-37, and 'a' through
57'z' for 38-63.
58.Pp
59The
60.Fn a64l
61function takes a pointer to a null-terminated radix-64 representation
62and returns a corresponding 32-bit value. If the string pointed to by
63.Ar s
64contains more than six characters,
65.Fn a64l
66will use the first six.
67.Fn A64l
68scans the character string from left to right, decoding
69each character as a 6-bit radix-64 number. If a long integer is
70larger than 32 bits, the return value will be sign-extended.
71.Pp
72.Fn l64a
73takes a long integer argument
74.Ar l
75and returns a pointer to the corresponding radix-64 representation.
76.Sh RETURN VALUES
77On success,
78.Fn a64l
79returns a 32-bit representation of
80.Ar s .
81If
82.Ar s
83is a NULL pointer or if it contains "digits" other than those described above,
84.Fn a64l
85returns -1L and sets the global variable errno to
86.Va EINVAL .
87.Pp
88On success,
89.Fn l64a
90returns a pointer to a string containing the radix-64 representation of
91.Ar l .
92If
93.Ar l
94is 0,
95.Fn l64a
96returns a pointer to the empty string.
97If
98.Ar l
99is negative,
100.Fn l64a
101returns a NULL pointer and sets the global variable errno to
102.Va EINVAL .
103.Sh WARNINGS
104The value returned by
105.Fn l64a
106is a pointer into a static buffer, the contents of which
107will be overwritten by subsequent calls.
108.Pp
109The value returned by
110.Fn a64l
111may be incorrect if the value is too large; for that reason, only strings
112that resulted from a call to
113.Fn l64a
114should be used to call
115.Fn a64l .
116.Pp
117If a long integer is larger than 32 bits, only the low-order
11832 bits are used.
119.Sh STANDARDS
120The
121.Fn a64l
122and
123.Fn l64a
124functions conform to
125.St -xpg4.2 .
diff --git a/src/lib/libc/stdlib/a64l.c b/src/lib/libc/stdlib/a64l.c
index 975e26ebb2..a68f0a6dcd 100644
--- a/src/lib/libc/stdlib/a64l.c
+++ b/src/lib/libc/stdlib/a64l.c
@@ -4,9 +4,12 @@
4 */ 4 */
5 5
6#if defined(LIBC_SCCS) && !defined(lint) 6#if defined(LIBC_SCCS) && !defined(lint)
7static char *rcsid = "$OpenBSD: a64l.c,v 1.2 1996/08/19 08:33:19 tholo Exp $"; 7static char *rcsid = "$OpenBSD: a64l.c,v 1.3 1997/08/17 22:58:34 millert Exp $";
8#endif /* LIBC_SCCS and not lint */ 8#endif /* LIBC_SCCS and not lint */
9 9
10#include <errno.h>
11#include <stdlib.h>
12
10long 13long
11a64l(s) 14a64l(s)
12 const char *s; 15 const char *s;
@@ -14,21 +17,30 @@ a64l(s)
14 long value, digit, shift; 17 long value, digit, shift;
15 int i; 18 int i;
16 19
20 if (s == NULL) {
21 errno = EINVAL;
22 return(-1L);
23 }
24
17 value = 0; 25 value = 0;
18 shift = 0; 26 shift = 0;
19 for (i = 0; *s && i < 6; i++, s++) { 27 for (i = 0; *s && i < 6; i++, s++) {
20 if (*s <= '/') 28 if (*s >= '.' && *s <= '/')
21 digit = *s - '.'; 29 digit = *s - '.';
22 else if (*s <= '9') 30 else if (*s >= '0' && *s <= '9')
23 digit = *s - '0' + 2; 31 digit = *s - '0' + 2;
24 else if (*s <= 'Z') 32 else if (*s >= 'A' && *s <= 'Z')
25 digit = *s - 'A' + 12; 33 digit = *s - 'A' + 12;
26 else 34 else if (*s >= 'a' && *s <= 'z')
27 digit = *s - 'a' + 38; 35 digit = *s - 'a' + 38;
36 else {
37 errno = EINVAL;
38 return(-1L);
39 }
28 40
29 value |= digit << shift; 41 value |= digit << shift;
30 shift += 6; 42 shift += 6;
31 } 43 }
32 44
33 return (long) value; 45 return(value);
34} 46}
diff --git a/src/lib/libc/stdlib/l64a.c b/src/lib/libc/stdlib/l64a.c
index 630f9e3365..4e99391254 100644
--- a/src/lib/libc/stdlib/l64a.c
+++ b/src/lib/libc/stdlib/l64a.c
@@ -4,13 +4,14 @@
4 */ 4 */
5 5
6#if defined(LIBC_SCCS) && !defined(lint) 6#if defined(LIBC_SCCS) && !defined(lint)
7static char *rcsid = "$OpenBSD: l64a.c,v 1.2 1996/08/19 08:33:33 tholo Exp $"; 7static char *rcsid = "$OpenBSD: l64a.c,v 1.3 1997/08/17 22:58:34 millert Exp $";
8#endif /* LIBC_SCCS and not lint */ 8#endif /* LIBC_SCCS and not lint */
9 9
10#include <errno.h>
10#include <stdlib.h> 11#include <stdlib.h>
11 12
12char * 13char *
13l64a (value) 14l64a(value)
14 long value; 15 long value;
15{ 16{
16 static char buf[8]; 17 static char buf[8];
@@ -18,8 +19,10 @@ l64a (value)
18 int digit; 19 int digit;
19 int i; 20 int i;
20 21
21 if (!value) 22 if (value < 0) {
22 return NULL; 23 errno = EINVAL;
24 return(NULL);
25 }
23 26
24 for (i = 0; value != 0 && i < 6; i++) { 27 for (i = 0; value != 0 && i < 6; i++) {
25 digit = value & 0x3f; 28 digit = value & 0x3f;
@@ -39,5 +42,5 @@ l64a (value)
39 42
40 *s = '\0'; 43 *s = '\0';
41 44
42 return buf; 45 return(buf);
43} 46}