mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 15:31:22 +01:00
lib: sbi: Simplify prints
When doing width = width - strlen(string) in prints there is no need to consider the case that witdh may be less than 0. This is because the code to do filling needs to be executed under the condition that width > 0. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -151,24 +151,11 @@ static void printc(char **out, u32 *out_len, char ch)
|
|||||||
static int prints(char **out, u32 *out_len, const char *string, int width,
|
static int prints(char **out, u32 *out_len, const char *string, int width,
|
||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
int pc = 0;
|
int pc = 0;
|
||||||
char padchar = ' ';
|
width -= sbi_strlen(string);
|
||||||
|
|
||||||
if (width > 0) {
|
|
||||||
int len = 0;
|
|
||||||
const char *ptr;
|
|
||||||
for (ptr = string; *ptr; ++ptr)
|
|
||||||
++len;
|
|
||||||
if (len >= width)
|
|
||||||
width = 0;
|
|
||||||
else
|
|
||||||
width -= len;
|
|
||||||
if (flags & PAD_ZERO)
|
|
||||||
padchar = '0';
|
|
||||||
}
|
|
||||||
if (!(flags & PAD_RIGHT)) {
|
if (!(flags & PAD_RIGHT)) {
|
||||||
for (; width > 0; --width) {
|
for (; width > 0; --width) {
|
||||||
printc(out, out_len, padchar);
|
printc(out, out_len, flags & PAD_ZERO ? '0' : ' ');
|
||||||
++pc;
|
++pc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,7 +164,7 @@ static int prints(char **out, u32 *out_len, const char *string, int width,
|
|||||||
++pc;
|
++pc;
|
||||||
}
|
}
|
||||||
for (; width > 0; --width) {
|
for (; width > 0; --width) {
|
||||||
printc(out, out_len, padchar);
|
printc(out, out_len, ' ');
|
||||||
++pc;
|
++pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user