@@ -137,6 +137,7 @@ extern "C" {
137
137
#define FLAGS_ADAPT_EXP (1U << 11U)
138
138
#define FLAGS_POINTER (1U << 12U)
139
139
// Note: Similar, but not identical, effect as FLAGS_HASH
140
+ typedef unsigned int printf_flags_t ;
140
141
141
142
#define BASE_BINARY 2
142
143
#define BASE_OCTAL 8
@@ -153,6 +154,9 @@ typedef long printf_signed_value_t;
153
154
154
155
typedef uint8_t numeric_base_t ;
155
156
157
+ typedef unsigned int printf_precision_t ;
158
+ typedef unsigned int printf_width_t ;
159
+
156
160
#if (PRINTF_SUPPORT_DECIMAL_SPECIFIERS || PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS )
157
161
#include <float.h>
158
162
#if FLT_RADIX != 2
@@ -266,11 +270,11 @@ static inline void out_wrapped_function(char character, void* wrapped_function,
266
270
267
271
// internal secure strlen
268
272
// @return The length of the string (excluding the terminating 0) limited by 'maxsize'
269
- static inline unsigned int strnlen_s_ (const char * str , size_t maxsize )
273
+ static inline size_t strnlen_s_ (const char * str , size_t maxsize )
270
274
{
271
275
const char * s ;
272
276
for (s = str ; * s && maxsize -- ; ++ s );
273
- return (unsigned int )(s - str );
277
+ return (size_t )(s - str );
274
278
}
275
279
276
280
@@ -294,7 +298,7 @@ static unsigned int atoi_(const char** str)
294
298
295
299
296
300
// output the specified string in reverse, taking care of any zero-padding
297
- static size_t out_rev_ (out_fct_type out , char * buffer , size_t idx , size_t maxlen , const char * buf , size_t len , unsigned int width , unsigned int flags )
301
+ static size_t out_rev_ (out_fct_type out , char * buffer , size_t idx , size_t maxlen , const char * buf , size_t len , printf_width_t width , printf_flags_t flags )
298
302
{
299
303
const size_t start_idx = idx ;
300
304
@@ -323,7 +327,7 @@ static size_t out_rev_(out_fct_type out, char* buffer, size_t idx, size_t maxlen
323
327
324
328
// Invoked by print_integer after the actual number has been printed, performing necessary
325
329
// work on the number's prefix (as the number is initially printed in reverse order)
326
- static size_t print_integer_finalization (out_fct_type out , char * buffer , size_t idx , size_t maxlen , char * buf , size_t len , bool negative , numeric_base_t base , unsigned int precision , unsigned int width , unsigned int flags )
330
+ static size_t print_integer_finalization (out_fct_type out , char * buffer , size_t idx , size_t maxlen , char * buf , size_t len , bool negative , numeric_base_t base , printf_precision_t precision , printf_width_t width , printf_flags_t flags )
327
331
{
328
332
size_t unpadded_len = len ;
329
333
@@ -390,7 +394,7 @@ static size_t print_integer_finalization(out_fct_type out, char* buffer, size_t
390
394
}
391
395
392
396
// An internal itoa-like function
393
- static size_t print_integer (out_fct_type out , char * buffer , size_t idx , size_t maxlen , printf_unsigned_value_t value , bool negative , numeric_base_t base , unsigned int precision , unsigned int width , unsigned int flags )
397
+ static size_t print_integer (out_fct_type out , char * buffer , size_t idx , size_t maxlen , printf_unsigned_value_t value , bool negative , numeric_base_t base , printf_precision_t precision , printf_width_t width , printf_flags_t flags )
394
398
{
395
399
char buf [PRINTF_INTEGER_BUFFER_SIZE ];
396
400
size_t len = 0U ;
@@ -441,7 +445,7 @@ static const double powers_of_10[NUM_DECIMAL_DIGITS_IN_INT64_T] = {
441
445
// Break up a double number - which is known to be a finite non-negative number -
442
446
// into its base-10 parts: integral - before the decimal point, and fractional - after it.
443
447
// Taken the precision into account, but does not change it even internally.
444
- static struct double_components get_components (double number , unsigned int precision )
448
+ static struct double_components get_components (double number , printf_precision_t precision )
445
449
{
446
450
struct double_components number_ ;
447
451
number_ .is_negative = get_sign (number );
@@ -516,7 +520,7 @@ static struct scaling_factor update_normalization(struct scaling_factor sf, doub
516
520
return result ;
517
521
}
518
522
519
- static struct double_components get_normalized_components (bool negative , unsigned int precision , double non_normalized , struct scaling_factor normalization )
523
+ static struct double_components get_normalized_components (bool negative , printf_precision_t precision , double non_normalized , struct scaling_factor normalization )
520
524
{
521
525
struct double_components components ;
522
526
components .is_negative = negative ;
@@ -556,8 +560,8 @@ static struct double_components get_normalized_components(bool negative, unsigne
556
560
#endif
557
561
558
562
static size_t print_broken_up_decimal (
559
- struct double_components number_ , out_fct_type out , char * buffer , size_t idx , size_t maxlen , unsigned int precision ,
560
- unsigned int width , unsigned int flags , char * buf , size_t len )
563
+ struct double_components number_ , out_fct_type out , char * buffer , size_t idx , size_t maxlen , printf_precision_t precision ,
564
+ printf_width_t width , printf_flags_t flags , char * buf , size_t len )
561
565
{
562
566
if (precision != 0U ) {
563
567
// do fractional part, as an unsigned number
@@ -638,15 +642,15 @@ static size_t print_broken_up_decimal(
638
642
}
639
643
640
644
// internal ftoa for fixed decimal floating point
641
- static size_t print_decimal_number (out_fct_type out , char * buffer , size_t idx , size_t maxlen , double number , unsigned int precision , unsigned int width , unsigned int flags , char * buf , size_t len )
645
+ static size_t print_decimal_number (out_fct_type out , char * buffer , size_t idx , size_t maxlen , double number , printf_precision_t precision , printf_width_t width , printf_flags_t flags , char * buf , size_t len )
642
646
{
643
647
struct double_components value_ = get_components (number , precision );
644
648
return print_broken_up_decimal (value_ , out , buffer , idx , maxlen , precision , width , flags , buf , len );
645
649
}
646
650
647
651
#if PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
648
652
// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <[email protected] >
649
- static size_t print_exponential_number (out_fct_type out , char * buffer , size_t idx , size_t maxlen , double number , unsigned int precision , unsigned int width , unsigned int flags , char * buf , size_t len )
653
+ static size_t print_exponential_number (out_fct_type out , char * buffer , size_t idx , size_t maxlen , double number , printf_precision_t precision , printf_width_t width , printf_flags_t flags , char * buf , size_t len )
650
654
{
651
655
const bool negative = get_sign (number );
652
656
// This number will decrease gradually (by factors of 10) as we "extract" the exponent out of it
@@ -737,9 +741,9 @@ static size_t print_exponential_number(out_fct_type out, char* buffer, size_t id
737
741
738
742
// the exp10 format is "E%+03d" and largest possible exp10 value for a 64-bit double
739
743
// is "307" (for 2^1023), so we set aside 4-5 characters overall
740
- unsigned int exp10_part_width = fall_back_to_decimal_only_mode ? 0U : (PRINTF_ABS (exp10 ) < 100 ) ? 4U : 5U ;
744
+ printf_width_t exp10_part_width = fall_back_to_decimal_only_mode ? 0U : (PRINTF_ABS (exp10 ) < 100 ) ? 4U : 5U ;
741
745
742
- unsigned int decimal_part_width =
746
+ printf_width_t decimal_part_width =
743
747
((flags & FLAGS_LEFT ) && exp10_part_width ) ?
744
748
// We're padding on the right, so the width constraint is the exponent part's
745
749
// problem, not the decimal part's, so we'll use as many characters as we need:
@@ -772,8 +776,7 @@ static size_t print_exponential_number(out_fct_type out, char* buffer, size_t id
772
776
}
773
777
#endif // PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
774
778
775
-
776
- static size_t print_floating_point (out_fct_type out , char * buffer , size_t idx , size_t maxlen , double value , unsigned int precision , unsigned int width , unsigned int flags , bool prefer_exponential )
779
+ static size_t print_floating_point (out_fct_type out , char * buffer , size_t idx , size_t maxlen , double value , printf_precision_t precision , printf_width_t width , printf_flags_t flags , bool prefer_exponential )
777
780
{
778
781
char buf [PRINTF_FTOA_BUFFER_SIZE ];
779
782
size_t len = 0U ;
@@ -821,7 +824,10 @@ static size_t print_floating_point(out_fct_type out, char* buffer, size_t idx, s
821
824
// internal vsnprintf
822
825
static int _vsnprintf (out_fct_type out , char * buffer , const size_t maxlen , const char * format , va_list va )
823
826
{
824
- unsigned int flags , width , precision , n ;
827
+ printf_flags_t flags ;
828
+ printf_width_t width ;
829
+ printf_precision_t precision ;
830
+ unsigned int n ;
825
831
size_t idx = 0U ;
826
832
827
833
if (!buffer ) {
@@ -865,10 +871,10 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
865
871
const int w = va_arg (va , int );
866
872
if (w < 0 ) {
867
873
flags |= FLAGS_LEFT ; // reverse padding
868
- width = (unsigned int )- w ;
874
+ width = (printf_width_t )- w ;
869
875
}
870
876
else {
871
- width = (unsigned int )w ;
877
+ width = (printf_width_t )w ;
872
878
}
873
879
format ++ ;
874
880
}
@@ -883,7 +889,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
883
889
}
884
890
else if (* format == '*' ) {
885
891
const int precision_ = va_arg (va , int );
886
- precision = precision_ > 0 ? (unsigned int )precision_ : 0U ;
892
+ precision = precision_ > 0 ? (printf_precision_t )precision_ : 0U ;
887
893
format ++ ;
888
894
}
889
895
}
@@ -1183,4 +1189,4 @@ int vfctprintf(void (*out)(char character, void* arg), void* arg, const char* fo
1183
1189
1184
1190
#ifdef __cplusplus
1185
1191
} // extern "C"
1186
- #endif
1192
+ #endif
0 commit comments