MCPcopy Create free account
hub / github.com/HelenOS/helenos / print_str

Function print_str

kernel/generic/src/printf/printf_core.c:280–317  ·  view source on GitHub ↗

Print string. * * @param str String to be printed. * @param width Width modifier. * @param precision Precision modifier. * @param flags Flags that modify the way the string is printed. * * @return Number of characters printed, negative value on failure. */

Source from the content-addressed store, hash-verified

278 * @return Number of characters printed, negative value on failure.
279 */
280static int print_str(char *str, int width, unsigned int precision,
281 uint32_t flags, printf_spec_t *ps)
282{
283 if (str == NULL)
284 return printf_putstr(nullstr, ps);
285
286 /* Print leading spaces. */
287 size_t strw = str_length(str);
288 if ((precision == 0) || (precision > strw))
289 precision = strw;
290
291 /* Left padding */
292 size_t counter = 0;
293 width -= precision;
294 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
295 while (width-- > 0) {
296 if (printf_putchar(' ', ps) == 1)
297 counter++;
298 }
299 }
300
301 /* Part of @a str fitting into the alloted space. */
302 int retval;
303 size_t size = str_lsize(str, precision);
304 if ((retval = printf_putnchars(str, size, ps)) < 0)
305 return -counter;
306
307 counter += retval;
308
309 /* Right padding */
310 while (width-- > 0) {
311 if (printf_putchar(' ', ps) == 1)
312 counter++;
313 }
314
315 return ((int) counter);
316
317}
318
319/** Print wide string.
320 *

Callers 1

printf_coreFunction · 0.70

Calls 5

printf_putstrFunction · 0.70
printf_putcharFunction · 0.70
printf_putncharsFunction · 0.70
str_lengthFunction · 0.50
str_lsizeFunction · 0.50

Tested by

no test coverage detected