19 for (sc = s; count-- && *sc !=
'\0'; ++
sc)
24 extern unsigned int __div64_32(
unsigned long long *dividend,
30 # define do_div(n,base) ({ \
31 unsigned int __base = (base); \
33 (void)(((typeof((n)) *)0) == ((unsigned long long *)0)); \
34 if (((n) >> 32) == 0) { \
35 __rem = (unsigned int)(n) % __base; \
36 (n) = (unsigned int)(n) / __base; \
38 __rem = __div64_32(&(n), __base); \
42 static int skip_atoi(
const char **
s)
46 for (i = 0;
'0' <= (c = **
s) && c <=
'9'; ++*
s)
59 static char *
number(
char *
str,
unsigned long long num,
int base,
int size,
int precision,
int type)
62 const char *digits=
"0123456789abcdefghijklmnopqrstuvwxyz";
66 digits =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
69 if (base < 2 || base > 36)
71 c = (type &
ZEROPAD) ?
'0' :
' ';
74 if ((
signed long long)num < 0) {
76 num = - (
signed long long)num;
78 }
else if (type &
PLUS) {
81 }
else if (type &
SPACE) {
95 else while (num != 0) {
96 tmp[i++] = digits[
do_div(num, base)];
106 if (type & SPECIAL) {
117 while (i < precision--)
129 unsigned long long num;
144 for (str=buf ; *
fmt ; ++
fmt) {
155 case '-': flags |=
LEFT;
goto repeat;
156 case '+': flags |=
PLUS;
goto repeat;
157 case ' ': flags |=
SPACE;
goto repeat;
158 case '#': flags |=
SPECIAL;
goto repeat;
159 case '0': flags |=
ZEROPAD;
goto repeat;
164 if (
'0' <= *fmt && *fmt <=
'9')
165 field_width = skip_atoi(&fmt);
166 else if (*fmt ==
'*') {
169 field_width =
va_arg(args,
int);
170 if (field_width < 0) {
171 field_width = -field_width;
180 if (
'0' <= *fmt && *fmt <=
'9')
181 precision = skip_atoi(&fmt);
182 else if (*fmt ==
'*') {
185 precision =
va_arg(args,
int);
193 if (*fmt ==
'l' && *(fmt + 1) ==
'l') {
196 }
else if (*fmt ==
'h' || *fmt ==
'l' || *fmt ==
'L'
208 while (--field_width > 0)
211 while (--field_width > 0)
223 while (len < field_width--)
225 for (i = 0; i < len; ++
i)
227 while (len < field_width--)
232 if (field_width == -1) {
233 field_width = 2*
sizeof(
void *);
237 (
unsigned long)
va_arg(args,
void *), 16,
238 field_width, precision, flags);
243 if (qualifier ==
'l') {
246 }
else if (qualifier ==
'Z') {
247 size_t *
ip =
va_arg(args,
size_t *);
284 if (qualifier ==
'l') {
285 num =
va_arg(args,
unsigned long);
287 num = (
signed long) num;
288 }
else if (qualifier ==
'q') {
289 num =
va_arg(args,
unsigned long long);
291 num = (
signed long long) num;
292 }
else if (qualifier ==
'Z') {
293 num =
va_arg(args,
size_t);
294 }
else if (qualifier ==
'h') {
297 num = (
signed short) num;
299 num =
va_arg(args,
unsigned int);
301 num = (
signed int) num;
303 str =
number(str, num, base, field_width, precision, flags);
320 static char sprint_buf[1024];
329 n =
vsprintf(sprint_buf, fmt, args);