MCPcopy Create free account
hub / github.com/SmingHub/Sming / m_vsnprintf

Function m_vsnprintf

Sming/System/m_printf.cpp:116–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116int m_vsnprintf(char *buf, size_t maxLen, const char *fmt, va_list args)
117{
118 size_t size = 0;
119 auto add = [&](char c) {
120 if (++size < maxLen) *buf++ = c;
121 };
122
123 while (*fmt) {
124 // copy verbatim text
125 if (*fmt != '%') {
126 add(*fmt++);
127 continue;
128 }
129 fmt++;
130
131 const char* s; // source for string copy
132 char tempNum[40]; // buffer for number conversion
133
134 // reset attributes to defaults
135 bool minus = 0;
136 uint8_t ubase = 0;
137 int8_t precision = -1;
138 int8_t width = 0;
139 char pad = ' ';
140 uint8_t length = 0;
141 bool upcase = false;
142
143 while (char f = *fmt) {
144 if (f == '-') minus = 1;
145 else if (f == '+') ; // ignored
146 else if (f == ' ') ; // ignored
147 else if (f == '#') ; // ignored
148 else break;
149 fmt++;
150 }
151
152 // process padding
153 if (*fmt == '0') {
154 pad = '0';
155 fmt++;
156 }
157
158 // process width ('*' is not supported yet)
159 if ( is_digit(*fmt) ) {
160 width = skip_atoi(&fmt);
161 }
162
163 // process precision
164 if( *fmt == '.' ) {
165 fmt++;
166 if ( is_digit(*fmt) ) precision = skip_atoi(&fmt);
167 }
168
169 // while (*fmt == 'l' || *fmt == 'h' || *fmt == 'L') fmt++;
170
171 // process length
172 do {
173 if ( *fmt == 'l' ) {

Callers 7

WRAP(vsnprintf)Function · 0.85
WRAP(snprintf)Function · 0.85
WRAP(vsprintf)Function · 0.85
WRAP(sprintf)Function · 0.85
m_snprintfFunction · 0.85
m_vprintfFunction · 0.85
printfMethod · 0.85

Calls 9

skip_atoiFunction · 0.85
isFlashPtrFunction · 0.85
ultoaFunction · 0.85
lltoa_wpFunction · 0.85
ltoa_wpFunction · 0.85
dtostrf_pFunction · 0.85
ulltoa_wpFunction · 0.85
ultoa_wpFunction · 0.85
str_upperFunction · 0.85

Tested by

no test coverage detected