MCPcopy Create free account
hub / github.com/coreboot/coreboot / print_string

Function print_string

payloads/libpayload/libc/printf.c:182–215  ·  view source on GitHub ↗

* Print string. * * @param s String to be printed. * @param width Width modifier. * @param precision Precision modifier. * @param flags Flags that modify the way the string is printed. * @param ps Output methods spec for different printf clones. * @return Number of characters printed, negative value on failure. */ Structure for specifying output methods for different printf clones. */

Source from the content-addressed store, hash-verified

180 */
181/** Structure for specifying output methods for different printf clones. */
182static int print_string(const char *s, int width, int precision,
183 uint64_t flags, struct printf_spec *ps)
184{
185 int counter = 0, retval;
186 size_t size;
187
188 if (s == NULL)
189 s = "(null)";
190 if (precision >= 0)
191 size = strnlen(s, precision);
192 else
193 size = strlen(s);
194 width -= size;
195
196 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
197 if ((retval = print_spaces(width, ps)) < 0)
198 return retval;
199 else
200 counter += retval;
201 }
202
203 if ((retval = printf_putnchars(s, size, ps)) < 0)
204 return retval;
205 counter += retval;
206
207 if (flags & __PRINTF_FLAG_LEFTALIGNED) {
208 if ((retval = print_spaces(width, ps)) < 0)
209 return retval;
210 else
211 counter += retval;
212 }
213
214 return counter;
215}
216
217/**
218 * Print a number in a given base.

Callers 1

printf_coreFunction · 0.70

Calls 4

strnlenFunction · 0.85
strlenFunction · 0.85
print_spacesFunction · 0.85
printf_putncharsFunction · 0.85

Tested by

no test coverage detected