39 #include <rtems/score/io.h> 41 #include <sys/cdefs.h> 42 __FBSDID(
"$FreeBSD: head/sys/kern/subr_prf.c 336417 2018-07-17 14:56:54Z markj $");
44 #include <sys/param.h> 48 #define MAXNBUF (howmany(sizeof(intmax_t) * NBBY, 3) + 1) 50 static inline int imax(
int a,
int b) {
return (a > b ? a : b); }
52 static char const hex2ascii_data[2][16] = {
53 {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
54 'a',
'b',
'c',
'd',
'e',
'f' },
55 {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
56 'A',
'B',
'C',
'D',
'E',
'F' }
63 return (hex2ascii_data[0][hex]);
73 ksprintn(
char *nbuf, uintmax_t num,
int base,
int *lenp,
int upper)
80 *++p = hex2ascii_data[upper][num % base];
81 }
while (num /= base);
88 _IO_Vprintf(IO_Put_char put_char,
void *arg,
char const *fmt, va_list ap)
90 #define PCHAR(c) {int cc=(c); (*put_char)(cc, arg); retval++; } 92 const char *p, *percent, *q;
96 int base, lflag, tmp, width, ladjust, sharpflag, neg, sign, dot;
97 int cflag, hflag, jflag;
99 #if __SIZEOF_PTRDIFF_T__ == __SIZEOF_LONG__ 104 #if __SIZEOF_SIZE_T__ == __SIZEOF_LONG__ 111 int stop = 0, retval = 0;
116 fmt =
"(fmt null)\n";
121 while ((ch = (u_char)*fmt++) !=
'%' || stop) {
127 lflag = 0; ladjust = 0; sharpflag = 0; neg = 0;
128 sign = 0; dot = 0; dwidth = 0; upper = 0;
129 cflag = 0; hflag = 0; jflag = 0; tflag = 0; zflag = 0;
130 reswitch:
switch (ch = (u_char)*fmt++) {
148 width = va_arg(ap,
int);
154 dwidth = va_arg(ap,
int);
163 case '1':
case '2':
case '3':
case '4':
164 case '5':
case '6':
case '7':
case '8':
case '9':
165 for (n = 0;; ++fmt) {
166 n = n * 10 + ch -
'0';
168 if (ch < '0' || ch >
'9')
179 if (!ladjust && width > 0)
182 PCHAR(va_arg(ap,
int));
183 if (ladjust && width > 0)
188 up = va_arg(ap, u_char *);
189 p = va_arg(ap,
char *);
193 PCHAR(hex2ascii(*up >> 4));
194 PCHAR(hex2ascii(*up & 0x0f));
227 sharpflag = (width == 0);
229 num = (uintptr_t)va_arg(ap,
void *);
232 p = va_arg(ap,
char *);
238 for (n = 0; n < dwidth && p[n]; n++)
243 if (!ladjust && width > 0)
248 if (ladjust && width > 0)
273 num = va_arg(ap, uintmax_t);
274 #if __SIZEOF_PTRDIFF_T__ != __SIZEOF_LONG__ 276 num = va_arg(ap, ptrdiff_t);
279 num = va_arg(ap, u_long);
280 #if __SIZEOF_SIZE_T__ != __SIZEOF_LONG__ 282 num = va_arg(ap,
size_t);
285 num = (u_short)va_arg(ap,
int);
287 num = (u_char)va_arg(ap,
int);
289 num = va_arg(ap, u_int);
293 num = va_arg(ap, intmax_t);
294 #if __SIZEOF_PTRDIFF_T__ == __SIZEOF_LONG__ 296 num = va_arg(ap, ptrdiff_t);
299 num = va_arg(ap,
long);
300 #if __SIZEOF_SIZE_T__ == __SIZEOF_LONG__ 302 num = va_arg(ap, ssize_t);
305 num = (short)va_arg(ap,
int);
307 num = (char)va_arg(ap,
int);
309 num = va_arg(ap,
int);
311 if (sign && (intmax_t)num < 0) {
313 num = -(intmax_t)num;
315 p = ksprintn(nbuf, num, base, &n, upper);
317 if (sharpflag && num != 0) {
326 if (!ladjust && padc ==
'0')
327 dwidth = width - tmp;
328 width -= tmp + imax(dwidth, n);
335 if (sharpflag && num != 0) {
338 }
else if (base == 16) {
355 while (percent < fmt)
#define RTEMS_STATIC_ASSERT(_cond, _msg)
Asserts at compile time that the specified condition is satisfied.