9 return c >=
'0' && c <=
'9';
44#define SPACE (1u << 2)
45#define ALTERNATE (1u << 3)
48#define UPPER (1u << 5)
49#define SIGNED (1u << 6)
74 int width,
int precision,
unsigned int flags)
76 static const char lower[] =
"0123456789abcdef";
77 static const char upper[] =
"0123456789ABCDEF";
78 const char *digits = (flags &
UPPER) ? upper : lower;
80 char tmp[24], prefix =
'\0';
85 if ( !(base == 8 || base == 10 || base == 16) )
89 if ( (flags &
LEFT) || (precision != -1) )
101 else if ( flags &
PLUS )
106 else if ( flags &
SPACE )
117 case 16: width -= 2;
break;
118 case 8: width -= 1;
break;
127 tmp[i++] = digits[
divmod64(&uval, base)];
136 while ( width-- > 0 )
147 case 16:
PUT(
'0');
PUT(
'x');
break;
148 case 8:
PUT(
'0');
break;
153 while ( width-- > 0 )
157 while ( i < precision-- )
172 int width,
int precision,
unsigned int flags)
184 if ( !(flags &
LEFT) )
185 while ( len < width-- )
188 for ( i = 0; i < len; ++i )
195 while ( len < width-- )
202 char *
str,
char *end,
const char **fmt_ptr,
const void *arg,
203 int width,
int precision,
unsigned int flags)
205 const char *fmt = *fmt_ptr;
211 const uint8_t *hex_buffer = arg;
261 arg, width, precision, flags) )
268 width = 2 *
sizeof(
void *);
273 width, precision, flags);
277 unsigned int caller_flags)
279 char *
str = buf, *end = buf + size;
281 for ( ; *fmt !=
'\0'; ++fmt )
283 const char *spec_start = fmt;
285 unsigned long long num;
286 unsigned int base, flags = caller_flags;
287 int width = -1, precision = -1;
288 char c, length_mod =
'i';
301 case '-': flags |=
LEFT;
goto next_flag;
302 case '+': flags |=
PLUS;
goto next_flag;
303 case ' ': flags |=
SPACE;
goto next_flag;
304 case '#': flags |=
ALTERNATE;
goto next_flag;
305 case '0': flags |=
ZERO;
goto next_flag;
312 width =
va_arg(args,
int);
336 precision =
va_arg(args,
int);
349 case 'h': length_mod =
'h'; ++fmt;
break;
350 case 'l': length_mod =
'l'; ++fmt;
break;
351 case 'z': length_mod =
'z'; ++fmt;
break;
356 case 'h': length_mod =
'H'; ++fmt;
break;
357 case 'l': length_mod =
'L'; ++fmt;
break;
370 if ( !(flags &
LEFT) )
371 while ( --width > 0 )
379 while ( --width > 0 )
386 width, precision, flags);
391 width, precision, flags);
421 switch ( length_mod )
425 num = (
signed char)
va_arg(args,
int);
427 num = (
unsigned char)
va_arg(args,
int);
432 num = (
signed short)
va_arg(args,
int);
434 num = (
unsigned short)
va_arg(args,
int);
439 num = (
signed int)
va_arg(args,
int);
441 num = (
unsigned int)
va_arg(args,
int);
450 num = (
signed long)
va_arg(args,
long);
452 num = (
unsigned long)
va_arg(args,
unsigned long);
457 num = (
signed long long)
va_arg(args,
long long);
459 num = (
unsigned long long)
va_arg(args,
unsigned long long);
static unsigned int str(void)
bool arch_fmt_pointer(char **str_ptr, char *end, const char **fmt_ptr, const void *arg, int width, int precision, unsigned int flags)
static uint32_t divmod64(uint64_t *dividend, uint32_t divisor)
__builtin_va_list va_list
size_t strnlen(const char *str, size_t max)
static char * pointer(char *str, char *end, const char **fmt_ptr, const void *arg, int width, int precision, unsigned int flags)
char * fmt_string(char *str, char *end, const char *val, int width, int precision, unsigned int flags)
static int fmt_int(const char **fmt)
int vsnprintf_internal(char *buf, size_t size, const char *fmt, va_list args, unsigned int caller_flags)
char * fmt_number(char *str, char *end, long long val, unsigned int base, int width, int precision, unsigned int flags)
static int isdigit(int c)