From 853fa4eed241cdd87b8c2d2e60cf755509d9a184 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 18 Nov 2021 17:25:58 +0100 Subject: sprintf improvements, added new _mem_init, GetSystemInfo --- libpsn00b/libc/vsprintf.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libpsn00b/libc/vsprintf.c') diff --git a/libpsn00b/libc/vsprintf.c b/libpsn00b/libc/vsprintf.c index 361b24e..0a99dcc 100644 --- a/libpsn00b/libc/vsprintf.c +++ b/libpsn00b/libc/vsprintf.c @@ -58,6 +58,15 @@ pad_quantity = (pad_quantity - 1) - last; \ if(pad_quantity < 0) pad_quantity = 0; +#define calculate_real_padding_bin() \ + last = 0; \ + for (x = 0; x < 32; x++) \ + if((arg >> x) & 1) \ + last = x; \ + \ + pad_quantity = (pad_quantity - 1) - last; \ + if(pad_quantity < 0) pad_quantity = 0; + #define write_padding() \ if(!(flags & SPRINTF_NEGFIELD_FLAG)) \ for(x = 0; x < pad_quantity; x++) \ @@ -703,6 +712,9 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap) //else // arg = va_arg(ap, unsigned long long); + calculate_real_padding_bin(); + write_padding(); + for(x=31;x>=0;x--) { y = (arg >> x); @@ -715,6 +727,8 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap) put_in_string(string, ssz, y + '0', string_pos++); } + write_neg_padding(); + directive_coming = 0; break; -- cgit v1.2.3