Commit Graph

9 Commits

Author SHA1 Message Date
anpeiyun eaa9401bf0 printf: fix printing error when the format specifier is "%*.f".
For %f with zero precision, omit decimal point and round to integer.
For example:
printf("%*.f",-14,321.7654321);    The true output is "322" intead of "321"

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
2026-04-21 01:34:25 +08:00
anpeiyun 0301101779 printf: fix printing error when the format specifier is "%.g".
Set default precision to 1 for %.g when precision is 0.
For example:
printf("%.g",-0.01);   the true output is "-0.01" intead of "-0.0"
printf("%.g",1.4);     the true output is "1" intead of "1.4"

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
2026-04-21 01:34:25 +08:00
anpeiyun 1e2e408964 printf: fix printing error when the format specifier is "%#g".
The '#' format flag retains trailing zeros and the decimal point
For example:
printf("%#g",5.0000001);     the true output is "5.000000" intead of "5.".

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
2026-04-21 01:34:24 +08:00
anpeiyun 572e798c66 printf: fix printing error when the precision is set to negative.
When a negative precision is passed in the format specifier of printf,
the printed result does not comply with POSIX requirements.
For example:
printf("%.*f",-4,321.7654321);            the true output is "321.765432" intead of "321"
printf("%*.*s",-14,-15,"test-string");    the true output is "test-string   " intead of "test-s        "

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
2026-04-21 01:34:24 +08:00
anpeiyun 41306a3bed printf: Add support for %a, %A, %n.a and %0n.a in printf()
Implement POSIX standard %a and %A format specifiers.
These specifiers output floating-point numbers in hexadecimal scientific notation, e.g., 0x1.ffffp+127.

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
2026-04-21 01:34:24 +08:00
anpeiyun 8540c3848f printf: add support for %ln, %n, and %hn.
The %n specifier stores the number of characters successfully output to the stream into a provided integer variable.
Refer to: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
2026-04-21 01:31:56 +08:00
yinshengkai 7f01f4be37 streams: rename lib_bsprintf to lib_osprintf
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2026-04-21 01:28:30 +08:00
Xiang Xiao ad9d0b9b4c libc: Merge lib_vsprintf from lib_libsprintf.c into lib_libvsprintf.c
since all other printf variants in lib_libvsprintf.c

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2026-04-21 01:24:40 +08:00
Xiang Xiao a27141641e libc: Move stream printf/scanf from libc/stdio to libc/stream
to keep all related code in one place

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2026-04-21 01:24:39 +08:00