1*bf198cc6Smillert.\" $OpenBSD: a64l.3,v 1.13 2019/01/25 00:19:25 millert Exp $ 206f01696Smillert.\" 3*bf198cc6Smillert.\" Copyright (c) 1997 Todd C. Miller <millert@openbsd.org> 4a8eb249eSmillert.\" 506f01696Smillert.\" Permission to use, copy, modify, and distribute this software for any 606f01696Smillert.\" purpose with or without fee is hereby granted, provided that the above 706f01696Smillert.\" copyright notice and this permission notice appear in all copies. 8a8eb249eSmillert.\" 9328f1f07Smillert.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10328f1f07Smillert.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11328f1f07Smillert.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12328f1f07Smillert.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13328f1f07Smillert.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14328f1f07Smillert.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15328f1f07Smillert.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16a8eb249eSmillert.\" 17*bf198cc6Smillert.Dd $Mdocdate: January 25 2019 $ 18a8eb249eSmillert.Dt A64L 3 19a8eb249eSmillert.Os 20a8eb249eSmillert.Sh NAME 21a8eb249eSmillert.Nm a64l , 22a8eb249eSmillert.Nm l64a 23a8eb249eSmillert.Nd convert between 32-bit integer and radix-64 ASCII string 24a8eb249eSmillert.Sh SYNOPSIS 2564d4e987Stedu.In stdlib.h 26a8eb249eSmillert.Ft long 27a8eb249eSmillert.Fn a64l "const char *s" 28a8eb249eSmillert.Ft char * 29a8eb249eSmillert.Fn l64a "long l" 30a8eb249eSmillert.Sh DESCRIPTION 31a8eb249eSmillertThe 32a8eb249eSmillert.Fn a64l 33a8eb249eSmillertand 34a8eb249eSmillert.Fn l64a 35a8eb249eSmillertfunctions are used to maintain numbers stored in radix-64 36c5a79f6dSaaron.Tn ASCII 37b43b9088Saaroncharacters. 38b43b9088SaaronThis is a notation by which 32-bit integers 39b43b9088Saaroncan be represented by up to six characters; each character represents a 40c5a79f6dSaaron.Dq digit 41c5a79f6dSaaronin a radix-64 notation. 42a8eb249eSmillert.Pp 43c5a79f6dSaaronThe characters used to represent digits are 44c5a79f6dSaaron.Ql \&. 45c5a79f6dSaaronfor 0, 46c5a79f6dSaaron.Ql / 47c5a79f6dSaaronfor 1, 48c5a79f6dSaaron.Ql 0 49c5a79f6dSaaronthrough 50c5a79f6dSaaron.Ql 9 51c5a79f6dSaaronfor 2-11, 52c5a79f6dSaaron.Ql A 53c5a79f6dSaaronthrough 54c5a79f6dSaaron.Ql Z 55c5a79f6dSaaronfor 12-37, and 56c5a79f6dSaaron.Ql a 57c5a79f6dSaaronthrough 58c5a79f6dSaaron.Ql z 59c5a79f6dSaaronfor 38-63. 60a8eb249eSmillert.Pp 61a8eb249eSmillertThe 62a8eb249eSmillert.Fn a64l 631e5ede29Scloderfunction takes a pointer to a NUL-terminated radix-64 representation 64b43b9088Saaronand returns a corresponding 32-bit value. 65b43b9088SaaronIf the string pointed to by 66c5a79f6dSaaron.Fa s 67a8eb249eSmillertcontains more than six characters, 68a8eb249eSmillert.Fn a64l 69a8eb249eSmillertwill use the first six. 70960f8fbdSderaadt.Fn a64l 71a8eb249eSmillertscans the character string from left to right, decoding 72b43b9088Saaroneach character as a 6-bit radix-64 number. 73b43b9088SaaronIf a long integer is 74a8eb249eSmillertlarger than 32 bits, the return value will be sign-extended. 75a8eb249eSmillert.Pp 76a8eb249eSmillert.Fn l64a 77a8eb249eSmillerttakes a long integer argument 78c5a79f6dSaaron.Fa l 79a8eb249eSmillertand returns a pointer to the corresponding radix-64 representation. 80a8eb249eSmillert.Sh RETURN VALUES 81a8eb249eSmillertOn success, 82a8eb249eSmillert.Fn a64l 83a8eb249eSmillertreturns a 32-bit representation of 84c5a79f6dSaaron.Fa s . 85a8eb249eSmillertIf 86c5a79f6dSaaron.Fa s 8707619a86Sjmcis a null pointer or if it contains digits other than those described above, 88a8eb249eSmillert.Fn a64l 89c5a79f6dSaaronreturns \-1 and sets the global variable 90c5a79f6dSaaron.Va errno 91c5a79f6dSaaronto 92c5a79f6dSaaron.Er EINVAL . 93a8eb249eSmillert.Pp 94a8eb249eSmillertOn success, 95a8eb249eSmillert.Fn l64a 96a8eb249eSmillertreturns a pointer to a string containing the radix-64 representation of 97c5a79f6dSaaron.Fa l . 98a8eb249eSmillertIf 99c5a79f6dSaaron.Fa l 100a8eb249eSmillertis 0, 101a8eb249eSmillert.Fn l64a 102a8eb249eSmillertreturns a pointer to the empty string. 103a8eb249eSmillertIf 104c5a79f6dSaaron.Fa l 105a8eb249eSmillertis negative, 106a8eb249eSmillert.Fn l64a 107c5a79f6dSaaronreturns a null pointer and sets the global variable 108c5a79f6dSaaron.Va errno 109c5a79f6dSaaronto 110c5a79f6dSaaron.Er EINVAL . 1110c1bb6b5Sjmc.Sh STANDARDS 1120c1bb6b5SjmcThe 1130c1bb6b5Sjmc.Fn a64l 1140c1bb6b5Sjmcand 1150c1bb6b5Sjmc.Fn l64a 1160c1bb6b5Sjmcfunctions conform to 1170c1bb6b5Sjmc.St -xpg4.2 . 1180c1bb6b5Sjmc.Sh CAVEATS 119a8eb249eSmillertThe value returned by 120a8eb249eSmillert.Fn l64a 121a8eb249eSmillertis a pointer into a static buffer, the contents of which 122a8eb249eSmillertwill be overwritten by subsequent calls. 123a8eb249eSmillert.Pp 124a8eb249eSmillertThe value returned by 125a8eb249eSmillert.Fn a64l 126a8eb249eSmillertmay be incorrect if the value is too large; for that reason, only strings 127a8eb249eSmillertthat resulted from a call to 128a8eb249eSmillert.Fn l64a 129a8eb249eSmillertshould be used to call 130a8eb249eSmillert.Fn a64l . 131a8eb249eSmillert.Pp 132a8eb249eSmillertIf a long integer is larger than 32 bits, only the low-order 133a8eb249eSmillert32 bits are used. 134