1
+ #include <string.h>
2
+
1
3
#include "example.h"
2
4
#include "parse_printf.h"
3
5
4
6
struct callback_info {
5
7
char * buffer_in ;
6
- uint64_t buffer_used ;
7
- uint64_t buffer_size ;
8
+ uint32_t buffer_used ;
9
+ uint32_t buffer_size ;
8
10
};
9
11
10
- uint64_t
12
+ uint32_t
11
13
format_to_buffer (char * const buffer_in ,
12
- const uint64_t buffer_len ,
14
+ const uint32_t buffer_len ,
13
15
const char * const format ,
14
16
...)
15
17
{
16
18
va_list list ;
17
19
va_start (list , format );
18
20
19
- const uint64_t result =
21
+ const uint32_t result =
20
22
vformat_to_buffer (buffer_in , buffer_len , format , list );
21
23
22
24
va_end (list );
23
25
return result ;
24
26
}
25
27
26
- static uint64_t
28
+ static uint32_t
27
29
format_to_buffer_write_ch_callback (
28
- const struct printf_spec_info * const spec_info ,
30
+ struct printf_spec_info * const spec_info ,
29
31
void * const info ,
30
32
const char ch ,
31
- uint64_t amount ,
33
+ uint32_t amount ,
32
34
bool * const should_continue_out )
33
35
{
34
36
(void )spec_info ;
35
37
36
38
struct callback_info * const cb_info = (struct callback_info * )info ;
37
- const uint64_t old_used = cb_info -> buffer_used ;
39
+ const uint32_t old_used = cb_info -> buffer_used ;
38
40
39
- uint64_t new_used = old_used ;
41
+ uint32_t new_used = old_used ;
40
42
if (__builtin_add_overflow (new_used , amount , & new_used )) {
41
43
* should_continue_out = false;
42
44
return 0 ;
43
45
}
44
46
45
- const uint64_t buffer_size = cb_info -> buffer_size ;
47
+ const uint32_t buffer_size = cb_info -> buffer_size ;
46
48
if (new_used >= buffer_size ) {
47
49
/*
48
50
* Truncate amount to just the space left if we don't have enough space
@@ -61,27 +63,27 @@ format_to_buffer_write_ch_callback(
61
63
return amount ;
62
64
}
63
65
64
- static uint64_t
66
+ static uint32_t
65
67
format_to_buffer_write_string_callback (
66
- const struct printf_spec_info * const spec_info ,
68
+ struct printf_spec_info * const spec_info ,
67
69
void * const info ,
68
70
const char * const string ,
69
- const uint64_t length ,
71
+ const uint32_t length ,
70
72
bool * const should_continue_out )
71
73
{
72
74
(void )spec_info ;
73
75
74
76
struct callback_info * const cb_info = (struct callback_info * )info ;
75
- const uint64_t old_used = cb_info -> buffer_used ;
77
+ const uint32_t old_used = cb_info -> buffer_used ;
76
78
77
- uint64_t new_used = old_used ;
79
+ uint32_t new_used = old_used ;
78
80
if (__builtin_add_overflow (new_used , length , & new_used )) {
79
81
* should_continue_out = false;
80
82
return 0 ;
81
83
}
82
84
83
- const uint64_t buffer_size = cb_info -> buffer_size ;
84
- uint64_t amount = length ;
85
+ const uint32_t buffer_size = cb_info -> buffer_size ;
86
+ uint32_t amount = length ;
85
87
86
88
if (new_used >= buffer_size ) {
87
89
/*
@@ -101,9 +103,9 @@ format_to_buffer_write_string_callback(
101
103
return amount ;
102
104
}
103
105
104
- uint64_t
106
+ uint32_t
105
107
vformat_to_buffer (char * const buffer_in ,
106
- const uint64_t buffer_len ,
108
+ const uint32_t buffer_len ,
107
109
const char * const format ,
108
110
va_list list )
109
111
{
@@ -118,7 +120,7 @@ vformat_to_buffer(char *const buffer_in,
118
120
.buffer_size = buffer_len - 1
119
121
};
120
122
121
- const uint64_t length =
123
+ const uint32_t length =
122
124
parse_printf_format (format_to_buffer_write_ch_callback ,
123
125
& cb_info ,
124
126
format_to_buffer_write_string_callback ,
@@ -130,11 +132,11 @@ vformat_to_buffer(char *const buffer_in,
130
132
return length ;
131
133
}
132
134
133
- static uint64_t
134
- get_length_ch_callback (const struct printf_spec_info * const spec_info ,
135
+ static uint32_t
136
+ get_length_ch_callback (struct printf_spec_info * const spec_info ,
135
137
void * const cb_info ,
136
138
const char ch ,
137
- const uint64_t times ,
139
+ const uint32_t times ,
138
140
bool * const should_continue_out )
139
141
{
140
142
(void )spec_info ;
@@ -146,11 +148,11 @@ get_length_ch_callback(const struct printf_spec_info *const spec_info,
146
148
return times ;
147
149
}
148
150
149
- static uint64_t
150
- get_length_string_callback (const struct printf_spec_info * const spec_info ,
151
+ static uint32_t
152
+ get_length_string_callback (struct printf_spec_info * const spec_info ,
151
153
void * const cb_info ,
152
154
const char * const string ,
153
- const uint64_t length ,
155
+ const uint32_t length ,
154
156
bool * const should_continue_out )
155
157
{
156
158
(void )spec_info ;
@@ -162,18 +164,18 @@ get_length_string_callback(const struct printf_spec_info *const spec_info,
162
164
return length ;
163
165
}
164
166
165
- uint64_t get_length_of_printf_format (const char * const fmt , ...) {
167
+ uint32_t get_length_of_printf_format (const char * const fmt , ...) {
166
168
va_list list ;
167
169
va_start (list , fmt );
168
170
169
- const uint64_t result = get_length_of_printf_vformat (fmt , list );
171
+ const uint32_t result = get_length_of_printf_vformat (fmt , list );
170
172
171
173
va_end (list );
172
174
return result ;
173
175
}
174
176
175
- uint64_t get_length_of_printf_vformat (const char * const fmt , va_list list ) {
176
- const uint64_t length =
177
+ uint32_t get_length_of_printf_vformat (const char * const fmt , va_list list ) {
178
+ const uint32_t length =
177
179
parse_printf_format (get_length_ch_callback ,
178
180
/*char_cb_info=*/ NULL ,
179
181
get_length_string_callback ,
0 commit comments