2 Copyright © 2018, The AROS Development Team. All rights reserved.
5 Prelude for common code block to format a string like printf().
11 # define BITSPERBYTE 8
14 #if (__WORDSIZE == 64)
15 /* On 64-bit machines long and long long are the same, so we don't need separate processing for long long */
16 #undef AROS_HAVE_LONG_LONG
19 #define MININTSIZE (sizeof(unsigned long)*BITSPERBYTE/3+1)
20 #define MINPOINTSIZE (sizeof(void *)*BITSPERBYTE/4+1)
21 #if defined(FULL_SPECIFIERS)
22 #define MINFLOATSIZE (DBL_DIG+1) /* Why not 1 more - it's 97% reliable */
23 #define REQUIREDBUFFER (MININTSIZE>MINPOINTSIZE? \
24 (MININTSIZE>MINFLOATSIZE?MININTSIZE:MINFLOATSIZE): \
25 (MINPOINTSIZE>MINFLOATSIZE?MINPOINTSIZE:MINFLOATSIZE))
27 #define REQUIREDBUFFER (MININTSIZE>MINPOINTSIZE ? (MININTSIZE) : (MINPOINTSIZE))
29 #define ALTERNATEFLAG 1 /* '#' is set */
30 #define ZEROPADFLAG 2 /* '0' is set */
31 #define LALIGNFLAG 4 /* '-' is set */
32 #define BLANKFLAG 8 /* ' ' is set */
33 #define SIGNFLAG 16 /* '+' is set */
34 #define LDBLFLAG 64 /* Processing a long double */
36 static size_t format_long(char *buffer
, char type
, int base
, unsigned long v
)
40 unsigned char mask
= 0;
41 unsigned char shift
= 0;
61 default: /* 'd' and 'u' */
62 /* Use slow divide operations for decimal numbers */
75 /* Divisor is a power of 2, so use fast shifts for division */
80 *--buffer
= (c
< 10) ? c
+ '0' : c
+ hex
;
88 #ifdef AROS_HAVE_LONG_LONG
91 * This is the same as format_long(), but takes long long argument.
92 * This is used to process long long values on 32-bit machines. 64-bit
93 * operations are performed slower there, and may need to call libgcc routines.
95 static size_t format_longlong(char *buffer
, char type
, int base
, unsigned long long v
)
99 unsigned char mask
= 0;
100 unsigned char shift
= 0;
123 * FIXME: this is not compiled for $(GENDIR)/lib32/librom.a because this requires
124 * __umoddi3() and __udivdi3() from 32-bit version of libgcc which is not supplied
125 * with 64-bit AROS gcc.
126 * Perhaps these routines needs to be implemented explicitly for the bootstrap. Or
127 * this code needs to be rewritten without these division operations, implementing
128 * decimal division explicitly.
129 * As a consequence, %llu and %lld do not work in x86-64 bootstrap. Use hexadecimal
130 * output or fix this.
150 *--buffer
= (c
< 10) ? c
+ '0' : c
+ hex
;