215 MOS_LIB_ASSERT(conv ==
'd' || conv ==
'i' || conv ==
'o' || conv ==
'u' || conv ==
'x' || conv ==
'X');
219 if (conv ==
'd' || conv ==
'i' || conv ==
'u')
223 mos_warn(
"'#' flag is ignored in d, i mode");
224 pflags->
hash =
false;
234 bool upper_case =
false;
235 const char *hex_digits =
NULL;
237 bool is_unsigned_ouxX = conv ==
'o' || conv ==
'u' || conv ==
'x' || conv ==
'X';
238 if (is_unsigned_ouxX)
242 mos_warn(
"'+' flag is ignored in unsigned mode");
247 mos_warn(
"' ' flag is ignored in unsigned mode");
251 base = (conv ==
'o' ? BASE_8 : (conv ==
'u' ? BASE_10 : BASE_16));
252 upper_case = conv ==
'X';
257 case LM_hh: number = (
u8) number;
break;
258 case LM__h: number = (
u16) number;
break;
260 case LM__l: number = (
u32) number;
break;
261 case LM_ll: number = (
u64) number;
break;
263 case LM__t: number = (ptrdiff_t) number;
break;
264 case LM__L: number = (
u64) number;
break;
278 char num_prefix_buf[5] = { 0 };
279 char num_content_buf[32] = { 0 };
280 size_t num_content_len = 32;
283 if (base == BASE_10 && !is_unsigned_ouxX)
285 bool is_negative = ((
s64) number) < 0;
287 number = -(
s64) number, num_prefix_buf[0] =
'-';
289 num_prefix_buf[0] =
'+';
291 num_prefix_buf[0] =
' ';
293 else if (base == BASE_16 && pflags->
hash)
299 num_prefix_buf[0] =
'0';
300 num_prefix_buf[1] = upper_case ?
'X' :
'x';
303 else if (base == BASE_8 && pflags->
hash)
316 num_content_buf[0] =
'0';
320 char *pnumberbuf = num_content_buf;
326 pnumberbuf +=
buf_putchar(pnumberbuf,
'0' + (
char) (number % base), &num_content_len), number /= base;
330 pnumberbuf +=
buf_putchar(pnumberbuf, hex_digits[number % 16], &num_content_len), number /= 16;
339 if (base == BASE_8 && pflags->
hash)
342 if (pflags->
precision - n_digits <= 0 && num_content_buf[0] !=
'0')
343 num_prefix_buf[0] =
'0';
350 char *pnum_prefix = num_prefix_buf;
351 char *pnum_content = num_content_buf + n_digits;
356 while (precision_padding-- > 0)
358 while (pnum_content > num_content_buf)
360 while (width_to_pad-- > 0)
370 while (width_to_pad-- > 0)
376 while (width_to_pad-- > 0)
381 while (precision_padding-- > 0)
383 while (pnum_content > num_content_buf)
size_t vsnprintf_do_pointer_kernel(char *buf, size_t *size, const char **pformat, ptr_t ptr)
Kernel's extension to vsnprintf, 'p' format specifier.