nshlib: correct ls -l command output format

Since the output format will be messed up with a size of GB.

before
```
ap> ls -l
/dev:
 brw-rw-rw-       0       0314572800 app
 dr--r--r--       0       0       0 audio/
 crw-rw-rw-       0       0       0 buttons
 crw-rw-rw-       0       0       0 console
 brw-rw-rw-       0       0104857600 coredump
 crw-rw-rw-       0       0       0 crypto
 brw-rw-rw-       0       02214592512 data
```

after
```
ap> ls -l
/dev:
 brw-rw-rw-       0       0   314572800 app
 dr--r--r--       0       0           0 audio/
 crw-rw-rw-       0       0           0 buttons
 crw-rw-rw-       0       0           0 console
 brw-rw-rw-       0       0   104857600 coredump
 crw-rw-rw-       0       0           0 crypto
 brw-rw-rw-       0       0  2214592512 data
```

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
This commit is contained in:
Junbo Zheng 2023-10-23 16:39:17 +08:00 committed by Xiang Xiao
parent e61ff51e67
commit c0da2b2a0e

View File

@ -290,20 +290,20 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
{
if (buf.st_size >= GB)
{
nsh_output(vtbl, "%7.1fG", (float)buf.st_size / GB);
nsh_output(vtbl, "%11.1fG", (float)buf.st_size / GB);
}
else if (buf.st_size >= MB)
{
nsh_output(vtbl, "%7.1fM", (float)buf.st_size / MB);
nsh_output(vtbl, "%11.1fM", (float)buf.st_size / MB);
}
else
{
nsh_output(vtbl, "%7.1fK", (float)buf.st_size / KB);
nsh_output(vtbl, "%11.1fK", (float)buf.st_size / KB);
}
}
else
{
nsh_output(vtbl, "%8" PRIdOFF, buf.st_size);
nsh_output(vtbl, "%12" PRIdOFF, buf.st_size);
}
}
}