63 #include <sys/types.h> 64 #define u_long unsigned long 65 #define u_short unsigned short 66 #define u_int unsigned int 68 #if !defined(HAVE_STDARG_PROTOTYPES) 70 #define HAVE_STDARG_PROTOTYPES 1 75 #if defined(HAVE_STDARG_PROTOTYPES) 88 #define _BSD_VA_LIST_ va_list 99 # define LONG_MAX 2147483647 104 #if defined(__hpux) && !defined(__GNUC__) && !defined(__STDC__) 114 #if defined(__hpux) && !defined(__GNUC__) || defined(__DECC) 118 #if !defined(__CYGWIN32__) && defined(__hpux) && !defined(__GNUC__) 126 #if SIZEOF_LONG > SIZEOF_INT 182 const char *(*vextra)();
186 #define __SLBF 0x0001 187 #define __SNBF 0x0002 192 #define __SEOF 0x0020 193 #define __SERR 0x0040 194 #define __SMBF 0x0080 195 #define __SAPP 0x0100 196 #define __SSTR 0x0200 197 #define __SOPT 0x0400 198 #define __SNPT 0x0800 199 #define __SOFF 0x1000 200 #define __SMOD 0x2000 206 #define BSD__sfeof(p) (((p)->_flags & __SEOF) != 0) 207 #define BSD__sferror(p) (((p)->_flags & __SERR) != 0) 208 #define BSD__sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 209 #define BSD__sfileno(p) ((p)->_file) 214 #define feof(p) BSD__sfeof(p) 215 #define ferror(p) BSD__sferror(p) 216 #define clearerr(p) BSD__sclearerr(p) 219 #define fileno(p) BSD__sfileno(p) 243 BSD__sfvwrite(
register FILE *fp,
register struct __suio *uio)
246 register const char *p;
247 register struct __siov *iov;
253 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 255 #define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n)) 261 #define GETIOV(extra_work) \ 265 len = iov->iov_len; \ 321 BSD__sprint(
FILE *fp,
register struct __suio *uio)
329 err = (*fp->
vwrite)(fp, uio);
342 BSD__sbprintf(
register FILE *fp,
const char *fmt, va_list ap)
352 #define to_digit(c) ((c) - '0') 353 #define is_digit(c) ((unsigned)to_digit(c) <= 9) 354 #define to_char(n) (char)((n) + '0') 356 #ifdef _HAVE_SANE_QUAD_ 364 BSD__uqtoa(
register u_quad_t
val,
char *endp,
int base,
int octzero,
const char *xdigs)
366 register char *cp = endp;
367 register quad_t sval;
385 if (val > LLONG_MAX) {
401 if (octzero && *cp !=
'0')
407 *--cp = xdigs[val & 15];
429 BSD__ultoa(
register u_long val,
char *endp,
int base,
int octzero,
const char *xdigs)
431 register char *cp = endp;
466 if (octzero && *cp !=
'0')
472 *--cp = xdigs[
val & 15];
486 #ifdef FLOATING_POINT 492 # if DBL_MAX_10_EXP > -DBL_MIN_10_EXP 493 # define MAXEXP (DBL_MAX_10_EXP) 495 # define MAXEXP (-DBL_MIN_10_EXP) 500 # define MAXFRACT (MAXEXP*10/3) 503 #define BUF (MAXEXP+MAXFRACT+1) 506 static char *cvt(
double,
int,
int,
char *,
int *,
int,
int *,
char *);
507 static int exponent(
char *,
int,
int);
515 #ifndef lower_hexdigits 516 # define lower_hexdigits "0123456789abcdef" 518 #ifndef upper_hexdigits 519 # define upper_hexdigits "0123456789ABCDEF" 526 #define HEXPREFIX 0x002 527 #define LADJUST 0x004 528 #define LONGDBL 0x008 529 #define LONGINT 0x010 531 #ifdef _HAVE_SANE_QUAD_ 532 #define QUADINT 0x020 535 #define SHORTINT 0x040 536 #define ZEROPAD 0x080 539 BSD_vfprintf(
FILE *fp,
const char *fmt0, va_list ap)
541 #ifdef PRI_EXTRA_MARK 544 register const char *fmt;
547 register const char *cp;
548 register struct __siov *iovp;
554 #ifdef FLOATING_POINT 564 #ifdef _HAVE_SANE_QUAD_ 572 const char *xdigs = 0;
578 char *
const ebuf = buf +
sizeof(
buf);
579 #if SIZEOF_LONG > SIZEOF_INT 589 static const char blanks[
PADSIZE] =
590 {
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' '};
591 static const char zeroes[
PADSIZE] =
592 {
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0'};
597 #define PRINT(ptr, len) { \ 598 iovp->iov_base = (ptr); \ 599 iovp->iov_len = (len); \ 600 uio.uio_resid += (len); \ 602 if (++uio.uio_iovcnt >= NIOV) { \ 603 if (BSD__sprint(fp, &uio)) \ 608 #define PAD(howmany, with) { \ 609 if ((n = (howmany)) > 0) { \ 610 while (n > PADSIZE) { \ 611 PRINT((with), PADSIZE); \ 617 #if SIZEOF_LONG > SIZEOF_INT 619 #define PAD_L(howmany, with) { \ 621 if ((long)((int)ln) != ln) { \ 625 if (ln > 0) PAD((int)ln, (with)); \ 628 #define PAD_L(howmany, with) PAD((howmany), (with)) 631 if (uio.uio_resid && BSD__sprint(fp, &uio)) \ 633 uio.uio_iovcnt = 0; \ 642 (flags&LONGINT ? va_arg(ap, long) : \ 643 flags&SHORTINT ? (long)(short)va_arg(ap, int) : \ 644 (long)va_arg(ap, int)) 646 (flags&LONGINT ? va_arg(ap, u_long) : \ 647 flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \ 648 (u_long)va_arg(ap, u_int)) 653 return (BSD__sbprintf(fp, fmt0, ap));
667 for (cp = fmt; (ch = *fmt) !=
'\0' && ch !=
'%'; fmt++)
669 if ((nc = fmt - cp) != 0) {
684 reswitch:
switch (ch) {
704 if ((width = va_arg(ap,
int)) >= 0)
715 if ((ch = *fmt++) ==
'*') {
717 prec = n < 0 ? -1 : n;
725 prec = n < 0 ? -1 : n;
735 case '1':
case '2':
case '3':
case '4':
736 case '5':
case '6':
case '7':
case '8':
case '9':
744 #ifdef FLOATING_POINT 752 #if SIZEOF_PTRDIFF_T == SIZEOF_LONG 755 #if SIZEOF_SIZE_T == SIZEOF_LONG 759 #ifdef _HAVE_SANE_QUAD_ 770 #ifdef _HAVE_SANE_QUAD_ 771 #if SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG 774 #if SIZEOF_SIZE_T == SIZEOF_LONG_LONG 783 if (*fmt ==
'3' && *(fmt + 1) ==
'2') {
787 #ifdef _HAVE_SANE_QUAD_ 788 else if (*fmt ==
'6' && *(fmt + 1) ==
'4') {
794 #if defined(_HAVE_SANE_QUAD_) && SIZEOF_SIZE_T == SIZEOF_LONG_LONG 803 *buf = (char)va_arg(ap,
int);
808 #ifdef _HAVE_SANE_QUAD_ 809 # define INTPTR_MASK (QUADINT|LONGINT|SHORTINT) 811 # define INTPTR_MASK (LONGINT|SHORTINT) 813 #if defined _HAVE_SANE_QUAD_ && SIZEOF_VOIDP == SIZEOF_LONG_LONG 814 # define INTPTR_FLAG QUADINT 815 #elif SIZEOF_VOIDP == SIZEOF_LONG 816 # define INTPTR_FLAG LONGINT 818 # define INTPTR_FLAG 0 820 #ifdef PRI_EXTRA_MARK 821 # define IS_PRI_EXTRA_MARK(s) \ 822 (PRI_EXTRA_MARK_LEN < 1 || \ 823 (*(s) == PRI_EXTRA_MARK[0] && \ 824 (PRI_EXTRA_MARK_LEN == 1 || \ 825 strncmp((s)+1, PRI_EXTRA_MARK+1, \ 826 PRI_EXTRA_MARK_LEN-1) == 0))) 828 # define PRI_EXTRA_MARK_LEN 0 829 # define IS_PRI_EXTRA_MARK(s) 1 835 #if defined _HAVE_SANE_QUAD_ && SIZEOF_VOIDP == SIZEOF_LONG_LONG 836 uqval = va_arg(ap, u_quad_t);
837 cp = (*fp->
vextra)(fp,
sizeof(uqval), &uqval, &fieldsz, sign);
839 ulval = va_arg(ap,
u_long);
840 cp = (*fp->
vextra)(fp,
sizeof(ulval), &ulval, &fieldsz, sign);
844 if (prec < 0)
goto long_len;
845 size = fieldsz < prec ? (int)fieldsz : prec;
854 #ifdef _HAVE_SANE_QUAD_ 855 if (flags & QUADINT) {
856 uqval = va_arg(ap, quad_t);
857 if ((quad_t)uqval < 0) {
858 uqval = -(quad_t)uqval;
865 if ((
long)ulval < 0) {
866 ulval = (
u_long)(-(
long)ulval);
872 #ifdef FLOATING_POINT 885 prec = (prec == -1) ?
886 DEFPREC + 1 : (fprec = prec + 1);
898 fp_begin: _double = va_arg(ap,
double);
900 if (
isinf(_double)) {
907 if (
isnan(_double)) {
913 cp = cvt(_double, (prec < MAXFRACT ? prec : MAXFRACT), flags, &softsign,
914 &expt, ch, &ndig, buf);
915 if (ch ==
'g' || ch ==
'G') {
916 if (expt <= -4 || (expt > prec && expt > 1))
917 ch = (ch ==
'g') ?
'e' :
'E';
921 if (ch ==
'a' || ch ==
'A') {
924 expsize = exponent(expstr, expt, ch +
'p' -
'a');
926 size = expsize + ndig;
927 if (ndig > 1 || flags &
ALT)
930 else if (ch <=
'e') {
932 expsize = exponent(expstr, expt, ch);
933 size = expsize + ndig;
934 if (ndig > 1 || flags &
ALT)
936 }
else if (ch ==
'f') {
939 if (prec || flags &
ALT)
947 }
else if (expt >= ndig) {
952 size = ndig + (expt > 0 ?
960 #ifdef _HAVE_SANE_QUAD_ 962 *va_arg(ap, quad_t *) = ret;
967 *va_arg(ap,
long *) = ret;
969 *va_arg(ap,
short *) = (short)ret;
971 *va_arg(ap,
int *) = (int)ret;
977 #ifdef _HAVE_SANE_QUAD_ 979 uqval = va_arg(ap, u_quad_t);
993 prec = (int)(
sizeof(
void*)*
CHAR_BIT/4);
995 uqval = (u_quad_t)va_arg(ap,
void *);
998 ulval = (
u_long)va_arg(ap,
void *);
999 #ifdef _HAVE_SANE_QUAD_ 1010 if ((cp = va_arg(ap,
char *)) ==
NULL)
1018 const char *p = (
char *)memchr(cp, 0, prec);
1020 if (p !=
NULL && (p - cp) < prec)
1021 size = (
int)(p - cp);
1035 #ifdef _HAVE_SANE_QUAD_ 1036 if (flags & QUADINT)
1037 uqval = va_arg(ap, u_quad_t);
1049 #ifdef _HAVE_SANE_QUAD_ 1050 if (flags & QUADINT)
1051 uqval = va_arg(ap, u_quad_t);
1058 #ifdef _HAVE_SANE_QUAD_
1059 (flags & QUADINT ? uqval != 0 : ulval != 0)
1067 nosign: sign =
'\0';
1073 number:
if ((dprec = prec) >= 0)
1082 #ifdef _HAVE_SANE_QUAD_ 1083 if (flags & QUADINT) {
1084 if (uqval != 0 || prec != 0)
1085 cp = BSD__uqtoa(uqval, ebuf, base,
1086 flags &
ALT, xdigs);
1091 if (ulval != 0 || prec != 0)
1092 cp = BSD__ultoa(ulval, ebuf, base,
1093 flags &
ALT, xdigs);
1095 size = (int)(ebuf - cp);
1124 realsz = dprec > fieldsz ? dprec : fieldsz;
1132 PAD_L(width - realsz, blanks);
1138 if (flags & HEXPREFIX) {
1146 PAD_L(width - realsz, zeroes);
1149 PAD_L(dprec - fieldsz, zeroes);
1152 #ifdef FLOATING_POINT 1153 if ((flags &
FPT) == 0) {
1156 if (flags & HEXPREFIX) {
1157 if (ndig > 1 || flags &
ALT) {
1161 if (ndig > 0)
PRINT(cp, ndig-1);
1164 PAD(fprec-ndig, zeroes);
1165 PRINT(expstr, expsize);
1167 else if (ch >=
'f') {
1171 (flags &
ALT) == 0) {
1175 PAD((ndig >= fprec ? ndig - 1 : fprec - (ch !=
'f')),
1178 }
else if (expt == 0 && ndig == 0 && (flags &
ALT) == 0) {
1180 }
else if (expt <= 0) {
1185 PAD(fprec - ndig + (ch ==
'f' ? expt : 0), zeroes);
1186 }
else if (expt >= ndig) {
1188 PAD(expt - ndig, zeroes);
1195 PRINT(cp, ndig-expt);
1197 PAD(fprec - ndig + (ch ==
'f' ? expt : 0), zeroes);
1200 if (ndig > 1 || flags &
ALT) {
1208 PAD(ndig - 1, zeroes);
1209 if (flags & ALT)
PAD(fprec - ndig - 1, zeroes);
1212 PRINT(expstr, expsize);
1220 PAD_L(width - realsz, blanks);
1223 ret += width > realsz ? width : realsz;
1234 #ifdef FLOATING_POINT 1236 extern char *
BSD__dtoa(
double,
int,
int,
int *,
int *,
char **);
1237 extern char *
BSD__hdtoa(
double,
const char *,
int,
int *,
int *,
char **);
1240 cvt(
double value,
int ndigits,
int flags,
char *sign,
int *decpt,
int ch,
int *length,
char *
buf)
1243 char *digits, *
bp, *rve;
1253 }
else if (value == 0.0 && 1.0/value < 0) {
1258 if (ch ==
'a' || ch ==
'A') {
1261 ndigits, decpt, &dsgn, &rve);
1264 digits =
BSD__dtoa(value, mode, ndigits, decpt, &dsgn, &rve);
1267 memcpy(buf, digits, rve - digits);
1269 rve = buf + (rve - digits);
1272 bp = digits + ndigits;
1274 if (*digits ==
'0' && value)
1275 *decpt = -ndigits + 1;
1281 *length = (int)(rve - digits);
1286 exponent(
char *p0,
int exp,
int fmtch)
1288 register char *p, *t;
1289 char expbuf[2 + (MAXEXP < 1000 ? 3 : MAXEXP < 10000 ? 4 : 5)];
1299 t = expbuf +
sizeof(expbuf);
1303 }
while ((exp /= 10) > 9);
1305 for (; t < expbuf +
sizeof(expbuf); *p++ = *t++);
1308 if (fmtch & 15) *p++ =
'0';
1311 return (
int)(p - p0);
size_t strlen(const char *)
#define IS_PRI_EXTRA_MARK(s)
#define PAD(howmany, with)
RUBY_EXTERN int isinf(double)
#define PAD_L(howmany, with)
#define rb_strlen_lit(str)
unsigned char buf[MIME_BUF_SIZE]
#define GETIOV(extra_work)
register unsigned int len
#define PRI_EXTRA_MARK_LEN