* Print formatted string. * * Print string formatted according to the fmt parameter and variadic arguments. * Each formatting directive must have the following form: * * \% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION * * FLAGS:@n * - "#" Force to print prefix.For \%o conversion, the prefix is 0, for * \%x and \%X prefixes are 0x and 0X and for conversion \%b the * prefix i
| 430 | * @return Number of characters printed, negative value on failure. |
| 431 | */ |
| 432 | static int printf_core(const char *fmt, struct printf_spec *ps, va_list ap) |
| 433 | { |
| 434 | int i = 0; /* Index of the currently processed char from fmt */ |
| 435 | int j = 0; /* Index to the first not printed nonformating character */ |
| 436 | int end; |
| 437 | int counter; /* Counter of printed characters */ |
| 438 | int retval; /* Used to store return values from called functions */ |
| 439 | char c; |
| 440 | qualifier_t qualifier; /* Type of argument */ |
| 441 | int base; /* Base in which a numeric parameter will be printed */ |
| 442 | uint64_t number; /* Argument value */ |
| 443 | size_t size; /* Byte size of integer parameter */ |
| 444 | int width, precision; |
| 445 | uint64_t flags; |
| 446 | |
| 447 | counter = 0; |
| 448 | |
| 449 | while ((c = fmt[i])) { |
| 450 | /* Control character. */ |
| 451 | if (c == '%') { |
| 452 | /* Print common characters if any processed. */ |
| 453 | if (i > j) { |
| 454 | if ((retval = printf_putnchars(&fmt[j], |
| 455 | (size_t) (i - j), ps)) < 0) |
| 456 | return retval; |
| 457 | counter += retval; |
| 458 | } |
| 459 | |
| 460 | j = i; |
| 461 | /* Parse modifiers. */ |
| 462 | flags = 0; |
| 463 | end = 0; |
| 464 | |
| 465 | do { |
| 466 | ++i; |
| 467 | switch (c = fmt[i]) { |
| 468 | case '#': |
| 469 | flags |= __PRINTF_FLAG_PREFIX; |
| 470 | break; |
| 471 | case '-': |
| 472 | flags |= __PRINTF_FLAG_LEFTALIGNED; |
| 473 | break; |
| 474 | case '+': |
| 475 | flags |= __PRINTF_FLAG_SHOWPLUS; |
| 476 | break; |
| 477 | case ' ': |
| 478 | flags |= __PRINTF_FLAG_SPACESIGN; |
| 479 | break; |
| 480 | case '0': |
| 481 | flags |= __PRINTF_FLAG_ZEROPADDED; |
| 482 | break; |
| 483 | default: |
| 484 | end = 1; |
| 485 | }; |
| 486 | |
| 487 | } while (end == 0); |
| 488 | |
| 489 | /* Width & '*' operator. */ |
no test coverage detected