66 #include "io_lib_config.h"
72 #include <sys/types.h>
79 #define MAX(a,b) ((a)>(b)?(a):(b))
83 #define ABS(a) ((a)>0?(a):-(a))
87 #define DEBUG_printf(a,n)
113 return vflen(fmt, args);
134 #if defined(HAVE_VA_COPY)
136 va_copy(ap_local, ap);
140 for(cp = fmt; *cp; cp++) {
146 long conv_len1=0, conv_len2=0, conv_len=0;
153 else if (
'-' == c ||
'+' == c ||
' ' == c)
160 l = strtol(cp, &endp, 10);
163 conv_len = conv_len1 = l;
164 }
else if (*cp ==
'*') {
165 conv_len = conv_len1 = (int)va_arg(ap,
int);
172 conv_len2 = strtol(cp, &endp, 10);
175 }
else if (*cp ==
'*') {
176 conv_len2 = (int)va_arg(ap,
int);
179 conv_len =
MAX(conv_len1, conv_len2);
186 }
else if (
'l' == *cp) {
204 len +=
MAX(conv_len1, 1);
215 l = (long)va_arg(ap,
int);
216 else if (arg_size == 1)
217 l = va_arg(ap,
long);
218 else if (arg_size == 2)
219 l = va_arg(ap,
long long);
221 l = (long)va_arg(ap,
int);
231 len +=
MAX(conv_len, 23);
241 len +=
MAX(conv_len1, 1);
245 d = va_arg(ap,
double);
257 l = (
ABS(d) > 1000000) ? 317 : 15;
258 l =
MAX(l, conv_len1 + 2);
259 if (conv_len2) l += conv_len2 - 6;
267 d = va_arg(ap,
double);
275 len +=
MAX(conv_len, 13);
279 l = (long)va_arg(ap,
void *);
285 len +=
MAX(conv_len, 20);
293 char *s = (
char *)va_arg(ap,
char *);
297 len +=
MAX(conv_len, (
int)strlen(s));
330 sprintf(buf,
"d: %d\n", 500);
331 l =
flen(
"d: %d\n", 500);
332 printf(
"%d %d\n\n", strlen(buf), l);
336 printf(
"%d %d\n\n", strlen(buf), l);
338 sprintf(buf,
"%s\n",
"test");
339 l =
flen(
"%s\n",
"test");
340 printf(
"%d %d\n\n", strlen(buf), l);
342 sprintf(buf,
"%c\n",
'a');
343 l =
flen(
"%c\n",
'a');
344 printf(
"%d %d\n\n", strlen(buf), l);
346 sprintf(buf,
"%31.30f\n", -9999.99);
347 l =
flen(
"%31.30f\n", -9999.99);
348 printf(
"%d %d\n\n", strlen(buf), l);
350 sprintf(buf,
"%f\n", -1e308);
351 l =
flen(
"%f\n", -1e308);
352 printf(
"%d %d\n\n", strlen(buf), l);
354 sprintf(buf,
"%.9f\n", -1e308);
355 l =
flen(
"%.9f\n", -1e308);
356 printf(
"%d %d\n\n", strlen(buf), l);
358 sprintf(buf,
"%10.20f\n", -1.999222333);
359 l =
flen(
"%10.20f\n", -1.999222333);
360 printf(
"%d %d\n\n", strlen(buf), l);
362 sprintf(buf,
"%#g\n", -3.14159265358e-222);
363 l =
flen(
"%#g\n", -3.1415927e-222);
364 printf(
"%d %d\n\n", strlen(buf), l);
366 sprintf(buf,
"%e\n", -123456789123456789.1);
367 l =
flen(
"%e\n", -123456789123456789.1);
368 printf(
"%d %d\n\n", strlen(buf), l);
370 sprintf(buf,
"%c %f %d %s %c %g %ld %s\n",
'a', 3.1, 9,
"one",
'b', 4.2, 9,
"two");
371 l =
flen(
"%c %f %d %s %c %g %ld %s\n",
'a', 3.1, 9,
"one",
'b', 4.2, 9,
"two");
372 printf(
"%d %d\n\n", strlen(buf), l);
374 sprintf(buf,
"%*.*e %*c\n", 10, 5, 9.0, 20,
'x');
375 l =
flen(
"%*.*e %*c\n", 10, 5, 9.0, 20,
'x');
376 printf(
"%d %d\n\n", strlen(buf), l);
378 sprintf(buf,
"%10c\n",
'z');
379 l =
flen(
"%10c\n",
'z');
380 printf(
"%d %d\n\n", strlen(buf), l);
382 sprintf(buf,
"%.10c\n",
'z');
383 l =
flen(
"%.10c\n",
'z');
384 printf(
"%d %d\n\n", strlen(buf), l);
386 sprintf(buf,
"%10d\n",
'z');
387 l =
flen(
"%10d\n",
'z');
388 printf(
"%d %d\n\n", strlen(buf), l);
390 sprintf(buf,
"%.10d\n",
'z');
391 l =
flen(
"%.10d\n",
'z');
392 printf(
"%d %d\n\n", strlen(buf), l);
394 sprintf(buf,
"%10%\n");
396 printf(
"%d %d\n\n", strlen(buf), l);
398 sprintf(buf,
"%.10%\n");
400 printf(
"%d %d\n\n", strlen(buf), l);
402 sprintf(buf,
"%s\n",
"0123456789");
403 l =
flen(
"%s\n",
"0123456789");
404 printf(
"%d %d\n\n", strlen(buf), l);
406 sprintf(buf,
"%5s\n",
"0123456789");
407 l =
flen(
"%5s\n",
"0123456789");
408 printf(
"%d %d\n\n", strlen(buf), l);
410 sprintf(buf,
"%50s\n",
"0123456789");
411 l =
flen(
"%50s\n",
"0123456789");
412 printf(
"%d %d\n\n", strlen(buf), l);
414 sprintf(buf,
"%.5s\n",
"0123456789");
415 l =
flen(
"%.5s\n",
"0123456789");
416 printf(
"%d %d\n\n", strlen(buf), l);
418 sprintf(buf,
"%.50s\n",
"0123456789");
419 l =
flen(
"%.50s\n",
"0123456789");
420 printf(
"%d %d\n\n", strlen(buf), l);
422 sprintf(buf,
"%5.50s\n",
"0123456789");
423 l =
flen(
"%5.50s\n",
"0123456789");
424 printf(
"%d %d\n\n", strlen(buf), l);
426 sprintf(buf,
"%50.5s\n",
"0123456789");
427 l =
flen(
"%50.5s\n",
"0123456789");
428 printf(
"%d %d\n\n", strlen(buf), l);