mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 23:41:23 +01:00
lib: sbi: Fix how print gets flags
The flags for print should be able to appear in any order. The previous code required the order to be fixed. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -236,6 +236,7 @@ static int printi(char **out, u32 *out_len, long long i, int b, int sg,
|
|||||||
|
|
||||||
static int print(char **out, u32 *out_len, const char *format, va_list args)
|
static int print(char **out, u32 *out_len, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
|
bool flags_done;
|
||||||
int width, flags, pc = 0;
|
int width, flags, pc = 0;
|
||||||
char scr[2], *tout;
|
char scr[2], *tout;
|
||||||
bool use_tbuf = (!out) ? true : false;
|
bool use_tbuf = (!out) ? true : false;
|
||||||
@@ -268,17 +269,24 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
|||||||
if (*format == '%')
|
if (*format == '%')
|
||||||
goto literal;
|
goto literal;
|
||||||
/* Get flags */
|
/* Get flags */
|
||||||
if (*format == '-') {
|
flags_done = false;
|
||||||
++format;
|
while (!flags_done) {
|
||||||
flags = PAD_RIGHT;
|
switch (*format) {
|
||||||
}
|
case '-':
|
||||||
if (*format == '#') {
|
flags |= PAD_RIGHT;
|
||||||
++format;
|
break;
|
||||||
flags |= PAD_ALTERNATE;
|
case '#':
|
||||||
}
|
flags |= PAD_ALTERNATE;
|
||||||
while (*format == '0') {
|
break;
|
||||||
++format;
|
case '0':
|
||||||
flags |= PAD_ZERO;
|
flags |= PAD_ZERO;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
flags_done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!flags_done)
|
||||||
|
++format;
|
||||||
}
|
}
|
||||||
/* Get width */
|
/* Get width */
|
||||||
for (; *format >= '0' && *format <= '9'; ++format) {
|
for (; *format >= '0' && *format <= '9'; ++format) {
|
||||||
|
Reference in New Issue
Block a user