38 #define is_digit(c) ((c) >= '0' && (c) <= '9')
40 static int skip_atoi(
const char **s) {
44 i = i * 10 + *((*s)++) -
'0';
56 #define do_div(n,base) ({ \
58 __asm__("divl %4":"=a" (n),"=d" (__res):"0" (n),"1" (0),"r" (base)); \
61 static char * number(
char * str,
int num,
int base,
int size,
int precision,
int type) {
62 char c, sign, tmp[36];
63 const char *digits =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
67 digits =
"0123456789abcdefghijklmnopqrstuvwxyz";
70 if (base < 2 || base > 36)
72 c = (type &
ZEROPAD) ?
'0' :
' ';
73 if ((type &
SIGN) && num < 0) {
78 sign = (type &
PLUS) ?
'+' : ((type &
SPACE) ?
' ' : 0);
94 tmp[i++] = digits[
do_div(num, base)];
107 else if (base == 16) {
115 while (i < precision--)
138 for (str =
buf; *fmt; ++fmt) {
168 field_width = skip_atoi(&fmt);
169 else if (*fmt ==
'*') {
171 field_width =
va_arg(args,
int);
172 if (field_width < 0) {
173 field_width = -field_width;
183 precision = skip_atoi(&fmt);
184 else if (*fmt ==
'*') {
186 precision =
va_arg(args,
int);
194 if (*fmt ==
'h' || *fmt ==
'l' || *fmt ==
'L') {
202 while (--field_width > 0)
204 *str++ = (
unsigned char)
va_arg(args,
int);
205 while (--field_width > 0)
214 else if (len > precision)
218 while (len < field_width--)
220 for (i = 0; i < len; ++i)
222 while (len < field_width--)
227 str = number(str,
va_arg(args,
unsigned long), 8, field_width, precision, flags);
231 if (field_width == -1) {
235 str = number(str, (
unsigned long)
va_arg(args,
void *), 16, field_width, precision, flags);
241 str = number(str,
va_arg(args,
unsigned long), 16, field_width, precision, flags);
248 str = number(str,
va_arg(args,
unsigned long), 10, field_width, precision, flags);