1
0
Fork 0
mirror of https://github.com/CTCaer/hekate.git synced 2024-11-13 22:06:46 +00:00

bdk: utils: add vprintf

This commit is contained in:
CTCaer 2022-01-20 12:37:41 +02:00
parent 10e1f67dc5
commit 82f90fae28
2 changed files with 68 additions and 1 deletions

View file

@ -133,3 +133,69 @@ out:
**sout_buf = '\0'; **sout_buf = '\0';
va_end(ap); va_end(ap);
} }
void s_vprintf(char *out_buf, const char *fmt, va_list ap)
{
int fill, fcnt;
sout_buf = &out_buf;
while(*fmt)
{
if(*fmt == '%')
{
fmt++;
fill = 0;
fcnt = 0;
if ((*fmt >= '0' && *fmt <= '9') || *fmt == ' ')
{
fcnt = *fmt;
fmt++;
if (*fmt >= '0' && *fmt <= '9')
{
fill = fcnt;
fcnt = *fmt - '0';
fmt++;
}
else
{
fill = ' ';
fcnt -= '0';
}
}
switch(*fmt)
{
case 'c':
_s_putc(va_arg(ap, u32));
break;
case 's':
_s_puts(va_arg(ap, char *));
break;
case 'd':
_s_putn(va_arg(ap, u32), 10, fill, fcnt);
break;
case 'p':
case 'P':
case 'x':
case 'X':
_s_putn(va_arg(ap, u32), 16, fill, fcnt);
break;
case '%':
_s_putc('%');
break;
case '\0':
goto out;
default:
_s_putc('%');
_s_putc(*fmt);
break;
}
}
else
_s_putc(*fmt);
fmt++;
}
out:
**sout_buf = '\0';
}

View file

@ -20,5 +20,6 @@
#include <utils/types.h> #include <utils/types.h>
void s_printf(char *out_buf, const char *fmt, ...); void s_printf(char *out_buf, const char *fmt, ...);
void s_vprintf(char *out_buf, const char *fmt, va_list ap);
#endif #endif