Ruby  2.1.10p492(2016-04-01revision54464)
vsnprintf.c
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 1990, 1993
3  * The Regents of the University of California. All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Chris Torek.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 /*
34  * IMPORTANT NOTE:
35  * --------------
36  * From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
37  * paragraph 3 above is now null and void.
38  */
39 
40 /* SNPRINTF.C
41  * fjc 7-31-97 Modified by Mib Software to be a standalone snprintf.c module.
42  * http://www.mibsoftware.com
43  * Mib Software does not warrant this software any differently than the
44  * University of California, Berkeley as described above. All warranties
45  * are disclaimed. Use this software at your own risk.
46  *
47  * All code referencing FILE * functions was eliminated, since it could
48  * never be called. All header files and necessary files are collapsed
49  * into one file, internal functions are declared static. This should
50  * allow inclusion into libraries with less chance of namespace collisions.
51  *
52  * snprintf should be the only externally visible item.
53  *
54  * As of 7-31-97 FLOATING_POINT is NOT provided. The code is somewhat
55  * non-portable, so it is disabled.
56  */
57 
58 /* Define FLOATING_POINT to get floating point. */
59 /*
60 #define FLOATING_POINT
61 */
62 
63 #include <sys/types.h>
64 #define u_long unsigned long
65 #define u_short unsigned short
66 #define u_int unsigned int
67 
68 #if !defined(HAVE_STDARG_PROTOTYPES)
69 #if defined(__STDC__)
70 #define HAVE_STDARG_PROTOTYPES 1
71 #endif
72 #endif
73 
74 #undef __P
75 #if defined(HAVE_STDARG_PROTOTYPES)
76 # include <stdarg.h>
77 # if !defined(__P)
78 # define __P(x) x
79 # endif
80 #else
81 # define __P(x) ()
82 # if !defined(const)
83 # define const
84 # endif
85 # include <varargs.h>
86 #endif
87 #ifndef _BSD_VA_LIST_
88 #define _BSD_VA_LIST_ va_list
89 #endif
90 
91 #ifdef __STDC__
92 # include <limits.h>
93 #else
94 # ifndef LONG_MAX
95 # ifdef HAVE_LIMITS_H
96 # include <limits.h>
97 # else
98  /* assuming 32bit(2's complement) long */
99 # define LONG_MAX 2147483647
100 # endif
101 # endif
102 #endif
103 
104 #if defined(__hpux) && !defined(__GNUC__) && !defined(__STDC__)
105 #define const
106 #endif
107 
108 #if defined(sgi)
109 #undef __const
110 #define __const
111 #endif /* People who don't like const sys_error */
112 
113 #include <stddef.h>
114 #if defined(__hpux) && !defined(__GNUC__) || defined(__DECC)
115 #include <string.h>
116 #endif
117 
118 #if !defined(__CYGWIN32__) && defined(__hpux) && !defined(__GNUC__)
119 #include <stdlib.h>
120 #endif
121 
122 #ifndef NULL
123 #define NULL 0
124 #endif
125 
126 #if SIZEOF_LONG > SIZEOF_INT
127 # include <errno.h>
128 #endif
129 
130 #if __GNUC__ >= 3
131 #define UNINITIALIZED_VAR(x) x = x
132 #else
133 #define UNINITIALIZED_VAR(x) x
134 #endif
135 
136 /*
137  * NB: to fit things in six character monocase externals, the stdio
138  * code uses the prefix `__s' for stdio objects, typically followed
139  * by a three-character attempt at a mnemonic.
140  */
141 
142 /* stdio buffers */
143 struct __sbuf {
144  unsigned char *_base;
145  size_t _size;
146 };
147 
148 
149 /*
150  * stdio state variables.
151  *
152  * The following always hold:
153  *
154  * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
155  * _lbfsize is -_bf._size, else _lbfsize is 0
156  * if _flags&__SRD, _w is 0
157  * if _flags&__SWR, _r is 0
158  *
159  * This ensures that the getc and putc macros (or inline functions) never
160  * try to write or read from a file that is in `read' or `write' mode.
161  * (Moreover, they can, and do, automatically switch from read mode to
162  * write mode, and back, on "r+" and "w+" files.)
163  *
164  * _lbfsize is used only to make the inline line-buffered output stream
165  * code as compact as possible.
166  *
167  * _ub, _up, and _ur are used when ungetc() pushes back more characters
168  * than fit in the current _bf, or when ungetc() pushes back a character
169  * that does not match the previous one in _bf. When this happens,
170  * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
171  * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
172  *
173  * NB: see WARNING above before changing the layout of this structure!
174  */
175 typedef struct __sFILE {
176  unsigned char *_p; /* current position in (some) buffer */
177 #if 0
178  size_t _r; /* read space left for getc() */
179 #endif
180  size_t _w; /* write space left for putc() */
181  short _flags; /* flags, below; this FILE is free if 0 */
182  short _file; /* fileno, if Unix descriptor, else -1 */
183  struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
184  size_t _lbfsize; /* 0 or -_bf._size, for inline putc */
185  int (*vwrite)(/* struct __sFILE*, struct __suio * */);
186  char *(*vextra)(/* struct __sFILE*, size_t, void*, long*, int */);
187 } FILE;
188 
189 
190 #define __SLBF 0x0001 /* line buffered */
191 #define __SNBF 0x0002 /* unbuffered */
192 #define __SRD 0x0004 /* OK to read */
193 #define __SWR 0x0008 /* OK to write */
194  /* RD and WR are never simultaneously asserted */
195 #define __SRW 0x0010 /* open for reading & writing */
196 #define __SEOF 0x0020 /* found EOF */
197 #define __SERR 0x0040 /* found error */
198 #define __SMBF 0x0080 /* _buf is from malloc */
199 #define __SAPP 0x0100 /* fdopen()ed in append mode */
200 #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
201 #define __SOPT 0x0400 /* do fseek() optimisation */
202 #define __SNPT 0x0800 /* do not do fseek() optimisation */
203 #define __SOFF 0x1000 /* set iff _offset is in fact correct */
204 #define __SMOD 0x2000 /* true => fgetln modified _p text */
205 
206 
207 #define EOF (-1)
208 
209 
210 #define BSD__sfeof(p) (((p)->_flags & __SEOF) != 0)
211 #define BSD__sferror(p) (((p)->_flags & __SERR) != 0)
212 #define BSD__sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
213 #define BSD__sfileno(p) ((p)->_file)
214 
215 #undef feof
216 #undef ferror
217 #undef clearerr
218 #define feof(p) BSD__sfeof(p)
219 #define ferror(p) BSD__sferror(p)
220 #define clearerr(p) BSD__sclearerr(p)
221 
222 #ifndef _ANSI_SOURCE
223 #define fileno(p) BSD__sfileno(p)
224 #endif
225 
226 
227 /*
228  * I/O descriptors for __sfvwrite().
229  */
230 struct __siov {
231  const void *iov_base;
232  size_t iov_len;
233 };
234 struct __suio {
235  struct __siov *uio_iov;
237  size_t uio_resid;
238 };
239 
240 /*
241  * Write some memory regions. Return zero on success, EOF on error.
242  *
243  * This routine is large and unsightly, but most of the ugliness due
244  * to the three different kinds of output buffering is handled here.
245  */
246 static int
247 BSD__sfvwrite(register FILE *fp, register struct __suio *uio)
248 {
249  register size_t len;
250  register const char *p;
251  register struct __siov *iov;
252  register size_t w;
253 
254  if ((len = uio->uio_resid) == 0)
255  return (0);
256 #ifndef __hpux
257 #define MIN(a, b) ((a) < (b) ? (a) : (b))
258 #endif
259 #define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n))
260 
261  iov = uio->uio_iov;
262  p = iov->iov_base;
263  len = iov->iov_len;
264  iov++;
265 #define GETIOV(extra_work) \
266  while (len == 0) { \
267  extra_work; \
268  p = iov->iov_base; \
269  len = iov->iov_len; \
270  iov++; \
271  }
272  if (fp->_flags & __SNBF) {
273  /* fjc 7-31-97 Will never happen. We are working with
274  strings only
275  */
276  } else if ((fp->_flags & __SLBF) == 0) {
277  /*
278  * Fully buffered: fill partially full buffer, if any,
279  * and then flush. If there is no partial buffer, write
280  * one _bf._size byte chunk directly (without copying).
281  *
282  * String output is a special case: write as many bytes
283  * as fit, but pretend we wrote everything. This makes
284  * snprintf() return the number of bytes needed, rather
285  * than the number used, and avoids its write function
286  * (so that the write function can be invalid).
287  */
288  do {
289  GETIOV(;);
290  w = fp->_w;
291  if (fp->_flags & __SSTR) {
292  if (len < w)
293  w = len;
294  COPY(w); /* copy MIN(fp->_w,len), */
295  fp->_w -= w;
296  fp->_p += w;
297  w = len; /* but pretend copied all */
298  } else {
299  /* fjc 7-31-97 Will never happen. We are working with
300  strings only
301  */
302  }
303  p += w;
304  len -= w;
305  } while ((uio->uio_resid -= w) != 0);
306  } else {
307  /* fjc 7-31-97 Will never happen. We are working with
308  strings only
309  */
310  }
311  return (0);
312 }
313 
314 /*
315  * Actual printf innards.
316  *
317  * This code is large and complicated...
318  */
319 
320 /*
321  * Flush out all the vectors defined by the given uio,
322  * then reset it so that it can be reused.
323  */
324 static int
325 BSD__sprint(FILE *fp, register struct __suio *uio)
326 {
327  register int err;
328 
329  if (uio->uio_resid == 0) {
330  uio->uio_iovcnt = 0;
331  return (0);
332  }
333  err = (*fp->vwrite)(fp, uio);
334  uio->uio_resid = 0;
335  uio->uio_iovcnt = 0;
336  return (err);
337 }
338 
339 
340 /*
341  * Helper function for `fprintf to unbuffered unix file': creates a
342  * temporary buffer. We only work on write-only files; this avoids
343  * worries about ungetc buffers and so forth.
344  */
345 static int
346 BSD__sbprintf(register FILE *fp, const char *fmt, va_list ap)
347 {
348 /* We don't support files. */
349  return 0;
350 }
351 
352 
353 /*
354  * Macros for converting digits to letters and vice versa
355  */
356 #define to_digit(c) ((c) - '0')
357 #define is_digit(c) ((unsigned)to_digit(c) <= 9)
358 #define to_char(n) (char)((n) + '0')
359 
360 #ifdef _HAVE_SANE_QUAD_
361 /*
362  * Convert an unsigned long long to ASCII for printf purposes, returning
363  * a pointer to the first character of the string representation.
364  * Octal numbers can be forced to have a leading zero; hex numbers
365  * use the given digits.
366  */
367 static char *
368 BSD__uqtoa(register u_quad_t val, char *endp, int base, int octzero, const char *xdigs)
369 {
370  register char *cp = endp;
371  register quad_t sval;
372 
373  /*
374  * Handle the three cases separately, in the hope of getting
375  * better/faster code.
376  */
377  switch (base) {
378  case 10:
379  if (val < 10) { /* many numbers are 1 digit */
380  *--cp = to_char(val);
381  return (cp);
382  }
383  /*
384  * On many machines, unsigned arithmetic is harder than
385  * signed arithmetic, so we do at most one unsigned mod and
386  * divide; this is sufficient to reduce the range of
387  * the incoming value to where signed arithmetic works.
388  */
389  if (val > LLONG_MAX) {
390  *--cp = to_char(val % 10);
391  sval = val / 10;
392  } else
393  sval = val;
394  do {
395  *--cp = to_char(sval % 10);
396  sval /= 10;
397  } while (sval != 0);
398  break;
399 
400  case 8:
401  do {
402  *--cp = to_char(val & 7);
403  val >>= 3;
404  } while (val);
405  if (octzero && *cp != '0')
406  *--cp = '0';
407  break;
408 
409  case 16:
410  do {
411  *--cp = xdigs[val & 15];
412  val >>= 4;
413  } while (val);
414  break;
415 
416  default: /* oops */
417  /*
418  abort();
419  */
420  break; /* fjc 7-31-97. Don't reference abort() here */
421  }
422  return (cp);
423 }
424 #endif /* _HAVE_SANE_QUAD_ */
425 
426 /*
427  * Convert an unsigned long to ASCII for printf purposes, returning
428  * a pointer to the first character of the string representation.
429  * Octal numbers can be forced to have a leading zero; hex numbers
430  * use the given digits.
431  */
432 static char *
433 BSD__ultoa(register u_long val, char *endp, int base, int octzero, const char *xdigs)
434 {
435  register char *cp = endp;
436  register long sval;
437 
438  /*
439  * Handle the three cases separately, in the hope of getting
440  * better/faster code.
441  */
442  switch (base) {
443  case 10:
444  if (val < 10) { /* many numbers are 1 digit */
445  *--cp = to_char(val);
446  return (cp);
447  }
448  /*
449  * On many machines, unsigned arithmetic is harder than
450  * signed arithmetic, so we do at most one unsigned mod and
451  * divide; this is sufficient to reduce the range of
452  * the incoming value to where signed arithmetic works.
453  */
454  if (val > LONG_MAX) {
455  *--cp = to_char(val % 10);
456  sval = val / 10;
457  } else
458  sval = val;
459  do {
460  *--cp = to_char(sval % 10);
461  sval /= 10;
462  } while (sval != 0);
463  break;
464 
465  case 8:
466  do {
467  *--cp = to_char(val & 7);
468  val >>= 3;
469  } while (val);
470  if (octzero && *cp != '0')
471  *--cp = '0';
472  break;
473 
474  case 16:
475  do {
476  *--cp = xdigs[val & 15];
477  val >>= 4;
478  } while (val);
479  break;
480 
481  default: /* oops */
482  /*
483  abort();
484  */
485  break; /* fjc 7-31-97. Don't reference abort() here */
486  }
487  return (cp);
488 }
489 
490 #ifdef FLOATING_POINT
491 #include <math.h>
492 #include <float.h>
493 /* #include "floatio.h" */
494 
495 #ifndef MAXEXP
496 # if DBL_MAX_10_EXP > -DBL_MIN_10_EXP
497 # define MAXEXP (DBL_MAX_10_EXP)
498 # else
499 # define MAXEXP (-DBL_MIN_10_EXP)
500 # endif
501 #endif
502 
503 #ifndef MAXFRACT
504 # define MAXFRACT (MAXEXP*10/3)
505 #endif
506 
507 #define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */
508 #define DEFPREC 6
509 
510 static char *cvt(double, int, int, char *, int *, int, int *, char *);
511 static int exponent(char *, int, int);
512 
513 #else /* no FLOATING_POINT */
514 
515 #define BUF 68
516 
517 #endif /* FLOATING_POINT */
518 
519 
520 /*
521  * Flags used during conversion.
522  */
523 #define ALT 0x001 /* alternate form */
524 #define HEXPREFIX 0x002 /* add 0x or 0X prefix */
525 #define LADJUST 0x004 /* left adjustment */
526 #define LONGDBL 0x008 /* long double; unimplemented */
527 #define LONGINT 0x010 /* long integer */
528 
529 #ifdef _HAVE_SANE_QUAD_
530 #define QUADINT 0x020 /* quad integer */
531 #endif /* _HAVE_SANE_QUAD_ */
532 
533 #define SHORTINT 0x040 /* short integer */
534 #define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
535 #define FPT 0x100 /* Floating point number */
536 static ssize_t
537 BSD_vfprintf(FILE *fp, const char *fmt0, va_list ap)
538 {
539  register const char *fmt; /* format string */
540  register int ch; /* character from fmt */
541  register int n; /* handy integer (short term usage) */
542  register const char *cp;/* handy char pointer (short term usage) */
543  register struct __siov *iovp;/* for PRINT macro */
544  register int flags; /* flags as above */
545  ssize_t ret; /* return value accumulator */
546  int width; /* width from format (%8d), or 0 */
547  int prec; /* precision from format (%.3d), or -1 */
548  char sign; /* sign prefix (' ', '+', '-', or \0) */
549 #ifdef FLOATING_POINT
550  char softsign; /* temporary negative sign for floats */
551  double _double = 0; /* double precision arguments %[eEfgG] */
552  int expt; /* integer value of exponent */
553  int expsize = 0; /* character count for expstr */
554  int ndig = 0; /* actual number of digits returned by cvt */
555  int fprec = 0; /* floating point precision */
556  char expstr[7]; /* buffer for exponent string */
557 #endif
558  u_long UNINITIALIZED_VAR(ulval); /* integer arguments %[diouxX] */
559 #ifdef _HAVE_SANE_QUAD_
560  u_quad_t UNINITIALIZED_VAR(uqval); /* %q integers */
561 #endif /* _HAVE_SANE_QUAD_ */
562  int base; /* base for [diouxX] conversion */
563  int dprec; /* a copy of prec if [diouxX], 0 otherwise */
564  long fieldsz; /* field size expanded by sign, etc */
565  long realsz; /* field size expanded by dprec */
566  int size; /* size of converted field or string */
567  const char *xdigs = 0; /* digits for [xX] conversion */
568 #define NIOV 8
569  struct __suio uio; /* output information: summary */
570  struct __siov iov[NIOV];/* ... and individual io vectors */
571  char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
572  char ox[4]; /* space for 0x hex-prefix, hexadecimal's 1. */
573  char *const ebuf = buf + sizeof(buf);
574 #if SIZEOF_LONG > SIZEOF_INT
575  long ln;
576 #endif
577 
578  /*
579  * Choose PADSIZE to trade efficiency vs. size. If larger printf
580  * fields occur frequently, increase PADSIZE and make the initializers
581  * below longer.
582  */
583 #define PADSIZE 16 /* pad chunk size */
584  static const char blanks[PADSIZE] =
585  {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
586  static const char zeroes[PADSIZE] =
587  {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
588 
589  /*
590  * BEWARE, these `goto error' on error, and PAD uses `n'.
591  */
592 #define PRINT(ptr, len) { \
593  iovp->iov_base = (ptr); \
594  iovp->iov_len = (len); \
595  uio.uio_resid += (len); \
596  iovp++; \
597  if (++uio.uio_iovcnt >= NIOV) { \
598  if (BSD__sprint(fp, &uio)) \
599  goto error; \
600  iovp = iov; \
601  } \
602 }
603 #define PAD(howmany, with) { \
604  if ((n = (howmany)) > 0) { \
605  while (n > PADSIZE) { \
606  PRINT((with), PADSIZE); \
607  n -= PADSIZE; \
608  } \
609  PRINT((with), n); \
610  } \
611 }
612 #if SIZEOF_LONG > SIZEOF_INT
613  /* abandon if too larger padding */
614 #define PAD_L(howmany, with) { \
615  ln = (howmany); \
616  if ((long)((int)ln) != ln) { \
617  errno = ENOMEM; \
618  goto error; \
619  } \
620  if (ln > 0) PAD((int)ln, (with)); \
621 }
622 #else
623 #define PAD_L(howmany, with) PAD((howmany), (with))
624 #endif
625 #define FLUSH() { \
626  if (uio.uio_resid && BSD__sprint(fp, &uio)) \
627  goto error; \
628  uio.uio_iovcnt = 0; \
629  iovp = iov; \
630 }
631 
632  /*
633  * To extend shorts properly, we need both signed and unsigned
634  * argument extraction methods.
635  */
636 #define SARG() \
637  (flags&LONGINT ? va_arg(ap, long) : \
638  flags&SHORTINT ? (long)(short)va_arg(ap, int) : \
639  (long)va_arg(ap, int))
640 #define UARG() \
641  (flags&LONGINT ? va_arg(ap, u_long) : \
642  flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \
643  (u_long)va_arg(ap, u_int))
644 
645  /* optimise fprintf(stderr) (and other unbuffered Unix files) */
646  if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
647  fp->_file >= 0)
648  return (BSD__sbprintf(fp, fmt0, ap));
649 
650  fmt = fmt0;
651  uio.uio_iov = iovp = iov;
652  uio.uio_resid = 0;
653  uio.uio_iovcnt = 0;
654  ret = 0;
655  xdigs = 0;
656 
657  /*
658  * Scan the format for conversions (`%' character).
659  */
660  for (;;) {
661  size_t nc;
662  for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
663  /* void */;
664  if ((nc = fmt - cp) != 0) {
665  PRINT(cp, nc);
666  ret += nc;
667  }
668  if (ch == '\0')
669  goto done;
670  fmt++; /* skip over '%' */
671 
672  flags = 0;
673  dprec = 0;
674  width = 0;
675  prec = -1;
676  sign = '\0';
677 
678 rflag: ch = *fmt++;
679 reswitch: switch (ch) {
680  case ' ':
681  /*
682  * ``If the space and + flags both appear, the space
683  * flag will be ignored.''
684  * -- ANSI X3J11
685  */
686  if (!sign)
687  sign = ' ';
688  goto rflag;
689  case '#':
690  flags |= ALT;
691  goto rflag;
692  case '*':
693  /*
694  * ``A negative field width argument is taken as a
695  * - flag followed by a positive field width.''
696  * -- ANSI X3J11
697  * They don't exclude field widths read from args.
698  */
699  if ((width = va_arg(ap, int)) >= 0)
700  goto rflag;
701  width = -width;
702  /* FALLTHROUGH */
703  case '-':
704  flags |= LADJUST;
705  goto rflag;
706  case '+':
707  sign = '+';
708  goto rflag;
709  case '.':
710  if ((ch = *fmt++) == '*') {
711  n = va_arg(ap, int);
712  prec = n < 0 ? -1 : n;
713  goto rflag;
714  }
715  n = 0;
716  while (is_digit(ch)) {
717  n = 10 * n + to_digit(ch);
718  ch = *fmt++;
719  }
720  prec = n < 0 ? -1 : n;
721  goto reswitch;
722  case '0':
723  /*
724  * ``Note that 0 is taken as a flag, not as the
725  * beginning of a field width.''
726  * -- ANSI X3J11
727  */
728  flags |= ZEROPAD;
729  goto rflag;
730  case '1': case '2': case '3': case '4':
731  case '5': case '6': case '7': case '8': case '9':
732  n = 0;
733  do {
734  n = 10 * n + to_digit(ch);
735  ch = *fmt++;
736  } while (is_digit(ch));
737  width = n;
738  goto reswitch;
739 #ifdef FLOATING_POINT
740  case 'L':
741  flags |= LONGDBL;
742  goto rflag;
743 #endif
744  case 'h':
745  flags |= SHORTINT;
746  goto rflag;
747 #if SIZEOF_PTRDIFF_T == SIZEOF_LONG
748  case 't':
749 #endif
750 #if SIZEOF_SIZE_T == SIZEOF_LONG
751  case 'z':
752 #endif
753  case 'l':
754 #ifdef _HAVE_SANE_QUAD_
755  if (*fmt == 'l') {
756  fmt++;
757  flags |= QUADINT;
758  } else {
759  flags |= LONGINT;
760  }
761 #else
762  flags |= LONGINT;
763 #endif
764  goto rflag;
765 #ifdef _HAVE_SANE_QUAD_
766 #if SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG
767  case 't':
768 #endif
769 #if SIZEOF_SIZE_T == SIZEOF_LONG_LONG
770  case 'z':
771 #endif
772  case 'q':
773  flags |= QUADINT;
774  goto rflag;
775 #endif /* _HAVE_SANE_QUAD_ */
776 #ifdef _WIN32
777  case 'I':
778  if (*fmt == '3' && *(fmt + 1) == '2') {
779  fmt += 2;
780  flags |= LONGINT;
781  }
782 #ifdef _HAVE_SANE_QUAD_
783  else if (*fmt == '6' && *(fmt + 1) == '4') {
784  fmt += 2;
785  flags |= QUADINT;
786  }
787 #endif
788  else
789 #if defined(_HAVE_SANE_QUAD_) && SIZEOF_SIZE_T == SIZEOF_LONG_LONG
790  flags |= QUADINT;
791 #else
792  flags |= LONGINT;
793 #endif
794  goto rflag;
795 #endif
796  case 'c':
797  cp = buf;
798  *buf = (char)va_arg(ap, int);
799  size = 1;
800  sign = '\0';
801  break;
802  case 'i':
803 #ifdef _HAVE_SANE_QUAD_
804 # define INTPTR_MASK (QUADINT|LONGINT|SHORTINT)
805 #else
806 # define INTPTR_MASK (LONGINT|SHORTINT)
807 #endif
808 #if defined _HAVE_SANE_QUAD_ && SIZEOF_VOIDP == SIZEOF_LONG_LONG
809 # define INTPTR_FLAG QUADINT
810 #elif SIZEOF_VOIDP == SIZEOF_LONG
811 # define INTPTR_FLAG LONGINT
812 #else
813 # define INTPTR_FLAG 0
814 #endif
815  if (fp->vextra && (flags & INTPTR_MASK) == INTPTR_FLAG) {
816  FLUSH();
817 #if defined _HAVE_SANE_QUAD_ && SIZEOF_VOIDP == SIZEOF_LONG_LONG
818  uqval = va_arg(ap, u_quad_t);
819  cp = (*fp->vextra)(fp, sizeof(uqval), &uqval, &fieldsz, sign);
820 #else
821  ulval = va_arg(ap, u_long);
822  cp = (*fp->vextra)(fp, sizeof(ulval), &ulval, &fieldsz, sign);
823 #endif
824  sign = '\0';
825  if (!cp) goto error;
826  if (prec < 0) goto long_len;
827  size = fieldsz < prec ? (int)fieldsz : prec;
828  break;
829  }
830  goto decimal;
831  case 'D':
832  flags |= LONGINT;
833  /*FALLTHROUGH*/
834  case 'd':
835  decimal:
836 #ifdef _HAVE_SANE_QUAD_
837  if (flags & QUADINT) {
838  uqval = va_arg(ap, quad_t);
839  if ((quad_t)uqval < 0) {
840  uqval = -(quad_t)uqval;
841  sign = '-';
842  }
843  } else
844 #endif /* _HAVE_SANE_QUAD_ */
845  {
846  ulval = SARG();
847  if ((long)ulval < 0) {
848  ulval = (u_long)(-(long)ulval);
849  sign = '-';
850  }
851  }
852  base = 10;
853  goto number;
854 #ifdef FLOATING_POINT
855  case 'a':
856  case 'A':
857  if (prec > 0) {
858  flags |= ALT;
859  prec++;
860  fprec = prec;
861  }
862  goto fp_begin;
863  case 'e': /* anomalous precision */
864  case 'E':
865  if (prec != 0)
866  flags |= ALT;
867  prec = (prec == -1) ?
868  DEFPREC + 1 : (fprec = prec + 1);
869  /* FALLTHROUGH */
870  goto fp_begin;
871  case 'f': /* always print trailing zeroes */
872  if (prec != 0)
873  flags |= ALT;
874  case 'g':
875  case 'G':
876  if (prec == -1)
877  prec = DEFPREC;
878  else
879  fprec = prec;
880 fp_begin: _double = va_arg(ap, double);
881  /* do this before tricky precision changes */
882  if (isinf(_double)) {
883  if (_double < 0)
884  sign = '-';
885  cp = "Inf";
886  size = 3;
887  break;
888  }
889  if (isnan(_double)) {
890  cp = "NaN";
891  size = 3;
892  break;
893  }
894  flags |= FPT;
895  cp = cvt(_double, (prec < MAXFRACT ? prec : MAXFRACT), flags, &softsign,
896  &expt, ch, &ndig, buf);
897  if (ch == 'g' || ch == 'G') {
898  if (expt <= -4 || (expt > prec && expt > 1))
899  ch = (ch == 'g') ? 'e' : 'E';
900  else
901  ch = 'g';
902  }
903  if (ch == 'a' || ch == 'A') {
904  flags |= HEXPREFIX;
905  --expt;
906  expsize = exponent(expstr, expt, ch + 'p' - 'a');
907  ch += 'x' - 'a';
908  size = expsize + ndig;
909  if (ndig > 1 || flags & ALT)
910  ++size; /* floating point */
911  }
912  else if (ch <= 'e') { /* 'e' or 'E' fmt */
913  --expt;
914  expsize = exponent(expstr, expt, ch);
915  size = expsize + ndig;
916  if (ndig > 1 || flags & ALT)
917  ++fprec, ++size;
918  } else if (ch == 'f') { /* f fmt */
919  if (expt > 0) {
920  size = expt;
921  if (prec || flags & ALT)
922  size += prec + 1;
923  } else if (!prec) { /* "0" */
924  size = 1;
925  if (flags & ALT)
926  size += 1;
927  } else /* "0.X" */
928  size = prec + 2;
929  } else if (expt >= ndig) { /* fixed g fmt */
930  size = expt;
931  if (flags & ALT)
932  ++size;
933  } else
934  size = ndig + (expt > 0 ?
935  1 : 2 - expt);
936 
937  if (softsign)
938  sign = '-';
939  break;
940 #endif /* FLOATING_POINT */
941  case 'n':
942 #ifdef _HAVE_SANE_QUAD_
943  if (flags & QUADINT)
944  *va_arg(ap, quad_t *) = ret;
945  else if (flags & LONGINT)
946 #else /* _HAVE_SANE_QUAD_ */
947  if (flags & LONGINT)
948 #endif /* _HAVE_SANE_QUAD_ */
949  *va_arg(ap, long *) = ret;
950  else if (flags & SHORTINT)
951  *va_arg(ap, short *) = (short)ret;
952  else
953  *va_arg(ap, int *) = (int)ret;
954  continue; /* no output */
955  case 'O':
956  flags |= LONGINT;
957  /*FALLTHROUGH*/
958  case 'o':
959 #ifdef _HAVE_SANE_QUAD_
960  if (flags & QUADINT)
961  uqval = va_arg(ap, u_quad_t);
962  else
963 #endif /* _HAVE_SANE_QUAD_ */
964  ulval = UARG();
965  base = 8;
966  goto nosign;
967  case 'p':
968  /*
969  * ``The argument shall be a pointer to void. The
970  * value of the pointer is converted to a sequence
971  * of printable characters, in an implementation-
972  * defined manner.''
973  * -- ANSI X3J11
974  */
975  prec = (int)(sizeof(void*)*CHAR_BIT/4);
976 #ifdef _HAVE_LLP64_
977  uqval = (u_quad_t)va_arg(ap, void *);
978  flags = (flags) | QUADINT | HEXPREFIX;
979 #else
980  ulval = (u_long)va_arg(ap, void *);
981 #ifdef _HAVE_SANE_QUAD_
982  flags = (flags & ~QUADINT) | HEXPREFIX;
983 #else /* _HAVE_SANE_QUAD_ */
984  flags = (flags) | HEXPREFIX;
985 #endif /* _HAVE_SANE_QUAD_ */
986 #endif
987  base = 16;
988  xdigs = "0123456789abcdef";
989  ch = 'x';
990  goto nosign;
991  case 's':
992  if ((cp = va_arg(ap, char *)) == NULL)
993  cp = "(null)";
994  if (prec >= 0) {
995  /*
996  * can't use strlen; can only look for the
997  * NUL in the first `prec' characters, and
998  * strlen() will go further.
999  */
1000  const char *p = (char *)memchr(cp, 0, prec);
1001 
1002  if (p != NULL && (p - cp) < prec)
1003  size = (int)(p - cp);
1004  else
1005  size = prec;
1006  }
1007  else {
1008  fieldsz = strlen(cp);
1009  goto long_len;
1010  }
1011  sign = '\0';
1012  break;
1013  case 'U':
1014  flags |= LONGINT;
1015  /*FALLTHROUGH*/
1016  case 'u':
1017 #ifdef _HAVE_SANE_QUAD_
1018  if (flags & QUADINT)
1019  uqval = va_arg(ap, u_quad_t);
1020  else
1021 #endif /* _HAVE_SANE_QUAD_ */
1022  ulval = UARG();
1023  base = 10;
1024  goto nosign;
1025  case 'X':
1026  xdigs = "0123456789ABCDEF";
1027  goto hex;
1028  case 'x':
1029  xdigs = "0123456789abcdef";
1030 hex:
1031 #ifdef _HAVE_SANE_QUAD_
1032  if (flags & QUADINT)
1033  uqval = va_arg(ap, u_quad_t);
1034  else
1035 #endif /* _HAVE_SANE_QUAD_ */
1036  ulval = UARG();
1037  base = 16;
1038  /* leading 0x/X only if non-zero */
1039  if (flags & ALT &&
1040 #ifdef _HAVE_SANE_QUAD_
1041  (flags & QUADINT ? uqval != 0 : ulval != 0)
1042 #else /* _HAVE_SANE_QUAD_ */
1043  ulval != 0
1044 #endif /* _HAVE_SANE_QUAD_ */
1045  )
1046  flags |= HEXPREFIX;
1047 
1048  /* unsigned conversions */
1049 nosign: sign = '\0';
1050  /*
1051  * ``... diouXx conversions ... if a precision is
1052  * specified, the 0 flag will be ignored.''
1053  * -- ANSI X3J11
1054  */
1055 number: if ((dprec = prec) >= 0)
1056  flags &= ~ZEROPAD;
1057 
1058  /*
1059  * ``The result of converting a zero value with an
1060  * explicit precision of zero is no characters.''
1061  * -- ANSI X3J11
1062  */
1063  cp = ebuf;
1064 #ifdef _HAVE_SANE_QUAD_
1065  if (flags & QUADINT) {
1066  if (uqval != 0 || prec != 0)
1067  cp = BSD__uqtoa(uqval, ebuf, base,
1068  flags & ALT, xdigs);
1069  } else
1070 #else /* _HAVE_SANE_QUAD_ */
1071 #endif /* _HAVE_SANE_QUAD_ */
1072  {
1073  if (ulval != 0 || prec != 0)
1074  cp = BSD__ultoa(ulval, ebuf, base,
1075  flags & ALT, xdigs);
1076  }
1077  size = (int)(ebuf - cp);
1078  break;
1079  default: /* "%?" prints ?, unless ? is NUL */
1080  if (ch == '\0')
1081  goto done;
1082  /* pretend it was %c with argument ch */
1083  cp = buf;
1084  *buf = ch;
1085  size = 1;
1086  sign = '\0';
1087  break;
1088  }
1089 
1090  /*
1091  * All reasonable formats wind up here. At this point, `cp'
1092  * points to a string which (if not flags&LADJUST) should be
1093  * padded out to `width' places. If flags&ZEROPAD, it should
1094  * first be prefixed by any sign or other prefix; otherwise,
1095  * it should be blank padded before the prefix is emitted.
1096  * After any left-hand padding and prefixing, emit zeroes
1097  * required by a decimal [diouxX] precision, then print the
1098  * string proper, then emit zeroes required by any leftover
1099  * floating precision; finally, if LADJUST, pad with blanks.
1100  *
1101  * Compute actual size, so we know how much to pad.
1102  * fieldsz excludes decimal prec; realsz includes it.
1103  */
1104  fieldsz = size;
1105 long_len:
1106  if (sign)
1107  fieldsz++;
1108  if (flags & HEXPREFIX)
1109  fieldsz += 2;
1110  realsz = dprec > fieldsz ? dprec : fieldsz;
1111 
1112  /* right-adjusting blank padding */
1113  if ((flags & (LADJUST|ZEROPAD)) == 0)
1114  PAD_L(width - realsz, blanks);
1115 
1116  /* prefix */
1117  if (sign) {
1118  PRINT(&sign, 1);
1119  }
1120  if (flags & HEXPREFIX) {
1121  ox[0] = '0';
1122  ox[1] = ch;
1123  PRINT(ox, 2);
1124  }
1125 
1126  /* right-adjusting zero padding */
1127  if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
1128  PAD_L(width - realsz, zeroes);
1129 
1130  /* leading zeroes from decimal precision */
1131  PAD_L(dprec - fieldsz, zeroes);
1132  if (sign)
1133  fieldsz--;
1134  if (flags & HEXPREFIX)
1135  fieldsz -= 2;
1136 
1137  /* the string or number proper */
1138 #ifdef FLOATING_POINT
1139  if ((flags & FPT) == 0) {
1140  PRINT(cp, fieldsz);
1141  } else { /* glue together f_p fragments */
1142  if (flags & HEXPREFIX) {
1143  if (ndig > 1 || flags & ALT) {
1144  ox[2] = *cp++;
1145  ox[3] = '.';
1146  PRINT(ox+2, 2);
1147  if (ndig > 0) PRINT(cp, ndig-1);
1148  } else /* XpYYY */
1149  PRINT(cp, 1);
1150  PAD(fprec-ndig, zeroes);
1151  PRINT(expstr, expsize);
1152  }
1153  else if (ch >= 'f') { /* 'f' or 'g' */
1154  if (_double == 0) {
1155  /* kludge for __dtoa irregularity */
1156  if (ndig <= 1 &&
1157  (flags & ALT) == 0) {
1158  PRINT("0", 1);
1159  } else {
1160  PRINT("0.", 2);
1161  PAD((ndig >= fprec ? ndig - 1 : fprec - (ch != 'f')),
1162  zeroes);
1163  }
1164  } else if (expt == 0 && ndig == 0 && (flags & ALT) == 0) {
1165  PRINT("0", 1);
1166  } else if (expt <= 0) {
1167  PRINT("0.", 2);
1168  PAD(-expt, zeroes);
1169  PRINT(cp, ndig);
1170  if (flags & ALT)
1171  PAD(fprec - ndig + (ch == 'f' ? expt : 0), zeroes);
1172  } else if (expt >= ndig) {
1173  PRINT(cp, ndig);
1174  PAD(expt - ndig, zeroes);
1175  if (flags & ALT)
1176  PRINT(".", 1);
1177  } else {
1178  PRINT(cp, expt);
1179  cp += expt;
1180  PRINT(".", 1);
1181  PRINT(cp, ndig-expt);
1182  if (flags & ALT)
1183  PAD(fprec - ndig + (ch == 'f' ? expt : 0), zeroes);
1184  }
1185  } else { /* 'e' or 'E' */
1186  if (ndig > 1 || flags & ALT) {
1187  ox[0] = *cp++;
1188  ox[1] = '.';
1189  PRINT(ox, 2);
1190  if (_double /*|| flags & ALT == 0*/) {
1191  PRINT(cp, ndig-1);
1192  } else /* 0.[0..] */
1193  /* __dtoa irregularity */
1194  PAD(ndig - 1, zeroes);
1195  if (flags & ALT) PAD(fprec - ndig - 1, zeroes);
1196  } else /* XeYYY */
1197  PRINT(cp, 1);
1198  PRINT(expstr, expsize);
1199  }
1200  }
1201 #else
1202  PRINT(cp, fieldsz);
1203 #endif
1204  /* left-adjusting padding (always blank) */
1205  if (flags & LADJUST)
1206  PAD_L(width - realsz, blanks);
1207 
1208  /* finally, adjust ret */
1209  ret += width > realsz ? width : realsz;
1210 
1211  FLUSH(); /* copy out the I/O vectors */
1212  }
1213 done:
1214  FLUSH();
1215 error:
1216  return (BSD__sferror(fp) ? EOF : ret);
1217  /* NOTREACHED */
1218 }
1219 
1220 #ifdef FLOATING_POINT
1221 
1222 extern char *BSD__dtoa(double, int, int, int *, int *, char **);
1223 extern char *BSD__hdtoa(double, const char *, int, int *, int *, char **);
1224 
1225 static char *
1226 cvt(double value, int ndigits, int flags, char *sign, int *decpt, int ch, int *length, char *buf)
1227 {
1228  int mode, dsgn;
1229  char *digits, *bp, *rve;
1230 
1231  if (ch == 'f')
1232  mode = 3;
1233  else {
1234  mode = 2;
1235  }
1236  if (value < 0) {
1237  value = -value;
1238  *sign = '-';
1239  } else if (value == 0.0 && 1.0/value < 0) {
1240  *sign = '-';
1241  } else {
1242  *sign = '\000';
1243  }
1244  if (ch == 'a' || ch =='A') {
1245  digits = BSD__hdtoa(value,
1246  ch == 'a' ? "0123456789abcdef" : "0123456789ABCDEF",
1247  ndigits, decpt, &dsgn, &rve);
1248  }
1249  else {
1250  digits = BSD__dtoa(value, mode, ndigits, decpt, &dsgn, &rve);
1251  }
1252  buf[0] = 0; /* rve - digits may be 0 */
1253  memcpy(buf, digits, rve - digits);
1254  xfree(digits);
1255  rve = buf + (rve - digits);
1256  digits = buf;
1257  if (flags & ALT) { /* Print trailing zeros */
1258  bp = digits + ndigits;
1259  if (ch == 'f') {
1260  if (*digits == '0' && value)
1261  *decpt = -ndigits + 1;
1262  bp += *decpt;
1263  }
1264  while (rve < bp)
1265  *rve++ = '0';
1266  }
1267  *length = (int)(rve - digits);
1268  return (digits);
1269 }
1270 
1271 static int
1272 exponent(char *p0, int exp, int fmtch)
1273 {
1274  register char *p, *t;
1275  char expbuf[2 + (MAXEXP < 1000 ? 3 : MAXEXP < 10000 ? 4 : 5)]; /* >= 2 + ceil(log10(MAXEXP)) */
1276 
1277  p = p0;
1278  *p++ = fmtch;
1279  if (exp < 0) {
1280  exp = -exp;
1281  *p++ = '-';
1282  }
1283  else
1284  *p++ = '+';
1285  t = expbuf + sizeof(expbuf);
1286  if (exp > 9) {
1287  do {
1288  *--t = to_char(exp % 10);
1289  } while ((exp /= 10) > 9);
1290  *--t = to_char(exp);
1291  for (; t < expbuf + sizeof(expbuf); *p++ = *t++);
1292  }
1293  else {
1294  if (fmtch & 15) *p++ = '0'; /* other than p or P */
1295  *p++ = to_char(exp);
1296  }
1297  return (int)(p - p0);
1298 }
1299 #endif /* FLOATING_POINT */
1300 
1301 int
1302 ruby_vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
1303 {
1304  int ret;
1305  FILE f;
1306 
1307  if ((int)n < 1)
1308  return (EOF);
1309  f._flags = __SWR | __SSTR;
1310  f._bf._base = f._p = (unsigned char *)str;
1311  f._bf._size = f._w = n - 1;
1312  f.vwrite = BSD__sfvwrite;
1313  f.vextra = 0;
1314  ret = (int)BSD_vfprintf(&f, fmt, ap);
1315  *f._p = 0;
1316  return (ret);
1317 }
1318 
1319 int
1320 ruby_snprintf(char *str, size_t n, char const *fmt, ...)
1321 {
1322  int ret;
1323  va_list ap;
1324  FILE f;
1325 
1326  if ((int)n < 1)
1327  return (EOF);
1328 
1329  va_start(ap, fmt);
1330  f._flags = __SWR | __SSTR;
1331  f._bf._base = f._p = (unsigned char *)str;
1332  f._bf._size = f._w = n - 1;
1333  f.vwrite = BSD__sfvwrite;
1334  f.vextra = 0;
1335  ret = (int)BSD_vfprintf(&f, fmt, ap);
1336  *f._p = 0;
1337  va_end(ap);
1338  return (ret);
1339 }
size_t strlen(const char *)
unsigned char * _base
Definition: vsnprintf.c:144
size_t _lbfsize
Definition: vsnprintf.c:184
#define __SSTR
Definition: vsnprintf.c:200
#define to_digit(c)
Definition: vsnprintf.c:356
#define BSD__hdtoa
Definition: sprintf.c:1125
#define HEXPREFIX
Definition: vsnprintf.c:524
short _file
Definition: vsnprintf.c:182
#define ZEROPAD
Definition: vsnprintf.c:534
#define LONGDBL
Definition: vsnprintf.c:526
const void * iov_base
Definition: vsnprintf.c:231
char *(* vextra)()
Definition: vsnprintf.c:186
int ruby_snprintf(char *str, size_t n, char const *fmt,...)
Definition: vsnprintf.c:1320
int uio_iovcnt
Definition: vsnprintf.c:236
#define NULL
Definition: vsnprintf.c:123
#define to_char(n)
Definition: vsnprintf.c:358
#define FLUSH()
#define LONG_MAX
Definition: vsnprintf.c:99
unsigned char * _p
Definition: vsnprintf.c:176
#define LONGINT
Definition: vsnprintf.c:527
#define SARG()
int t(void)
Definition: conftest.c:13
static int BSD__sfvwrite(register FILE *fp, register struct __suio *uio)
Definition: vsnprintf.c:247
#define val
#define INTPTR_MASK
#define UNINITIALIZED_VAR(x)
Definition: vsnprintf.c:133
#define __SWR
Definition: vsnprintf.c:193
#define PAD(howmany, with)
int ruby_vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
Definition: vsnprintf.c:1302
RUBY_EXTERN int isinf(double)
Definition: isinf.c:56
short _flags
Definition: vsnprintf.c:181
int err
Definition: win32.c:114
#define __SLBF
Definition: vsnprintf.c:190
#define EOF
Definition: vsnprintf.c:207
#define PAD_L(howmany, with)
#define LADJUST
Definition: vsnprintf.c:525
#define PADSIZE
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4308
size_t uio_resid
Definition: vsnprintf.c:237
#define GETIOV(extra_work)
struct __siov * uio_iov
Definition: vsnprintf.c:235
#define isnan(x)
Definition: win32.h:376
struct __sFILE FILE
#define CHAR_BIT
Definition: ruby.h:198
#define NIOV
static int BSD__sbprintf(register FILE *fp, const char *fmt, va_list ap)
Definition: vsnprintf.c:346
int size
Definition: encoding.c:49
#define f
static ssize_t BSD_vfprintf(FILE *fp, const char *fmt0, va_list ap)
Definition: vsnprintf.c:537
#define BUF
Definition: vsnprintf.c:515
size_t _size
Definition: vsnprintf.c:145
#define is_digit(c)
Definition: vsnprintf.c:357
size_t _w
Definition: vsnprintf.c:180
#define FPT
Definition: vsnprintf.c:535
#define BSD__dtoa
Definition: sprintf.c:1124
#define ALT
Definition: vsnprintf.c:523
static char * BSD__ultoa(register u_long val, char *endp, int base, int octzero, const char *xdigs)
Definition: vsnprintf.c:433
#define u_long
Definition: vsnprintf.c:64
struct __sbuf _bf
Definition: vsnprintf.c:183
#define PRINT(ptr, len)
void void xfree(void *)
#define __SNBF
Definition: vsnprintf.c:191
#define UARG()
#define INTPTR_FLAG
int(* vwrite)()
Definition: vsnprintf.c:185
#define SHORTINT
Definition: vsnprintf.c:533
#define BSD__sferror(p)
Definition: vsnprintf.c:211
#define bp()
Definition: vm_debug.h:25
#define COPY(n)
static int BSD__sprint(FILE *fp, register struct __suio *uio)
Definition: vsnprintf.c:325
#define __SRW
Definition: vsnprintf.c:195
size_t iov_len
Definition: vsnprintf.c:232