2002-05-07 04:44:54 +08:00
|
|
|
/* l64a - convert long to radix-64 ascii string
|
|
|
|
*
|
|
|
|
* Conversion is performed on at most 32-bits of input value starting
|
|
|
|
* from least significant bits to the most significant bits.
|
|
|
|
*
|
|
|
|
* The routine splits the input value into groups of 6 bits for up to
|
|
|
|
* 32 bits of input. This means that the last group may be 2 bits
|
|
|
|
* (bits 30 and 31).
|
|
|
|
*
|
|
|
|
* Each group of 6 bits forms a value from 0-63 which is converted into
|
|
|
|
* a character as follows:
|
|
|
|
* 0 = '.'
|
|
|
|
* 1 = '/'
|
|
|
|
* 2-11 = '0' to '9'
|
|
|
|
* 12-37 = 'A' to 'Z'
|
|
|
|
* 38-63 = 'a' to 'z'
|
|
|
|
*
|
|
|
|
* When the remaining bits are zero or all 32 bits have been translated,
|
|
|
|
* a nul terminator is appended to the resulting string. An input value of
|
|
|
|
* 0 results in an empty string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <_ansi.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <reent.h>
|
|
|
|
|
Add --enable-newlib-reent-thread-local option
By default, Newlib uses a huge object of type struct _reent to store
thread-specific data. This object is returned by __getreent() if the
__DYNAMIC_REENT__ Newlib configuration option is defined.
The reentrancy structure contains for example errno and the standard input,
output, and error file streams. This means that if an application only uses
errno it has a dependency on the file stream support even if it does not use
it. This is an issue for lower end targets and applications which need to
qualify the software according to safety standards (for example ECSS-E-ST-40C,
ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333).
If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct
_reent is replaced by dedicated thread-local objects for each struct _reent
member. The thread-local objects are defined in translation units which use
the corresponding object.
2022-05-16 17:51:54 +08:00
|
|
|
#ifdef _REENT_THREAD_LOCAL
|
|
|
|
_Thread_local char _tls_l64a_buf[8];
|
|
|
|
#endif
|
|
|
|
|
2002-05-07 04:44:54 +08:00
|
|
|
static const char R64_ARRAY[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
|
|
|
char *
|
2017-12-04 11:43:30 +08:00
|
|
|
l64a (long value)
|
2002-05-07 04:44:54 +08:00
|
|
|
{
|
|
|
|
return _l64a_r (_REENT, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2017-12-04 11:43:30 +08:00
|
|
|
_l64a_r (struct _reent *rptr,
|
2002-05-07 04:44:54 +08:00
|
|
|
long value)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
char *result;
|
|
|
|
int i, index;
|
|
|
|
unsigned long tmp = (unsigned long)value & 0xffffffff;
|
|
|
|
|
|
|
|
_REENT_CHECK_MISC(rptr);
|
|
|
|
result = _REENT_L64A_BUF(rptr);
|
|
|
|
ptr = result;
|
|
|
|
|
|
|
|
for (i = 0; i < 6; ++i)
|
|
|
|
{
|
|
|
|
if (tmp == 0)
|
|
|
|
{
|
|
|
|
*ptr = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = tmp & (64 - 1);
|
|
|
|
*ptr++ = R64_ARRAY[index];
|
|
|
|
tmp >>= 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|