SCCS-vsn: lib/libc/stdio/vfprintf.c 5.49
SCCS-vsn: lib/libc/stdio/printf.3 6.15
.\"
.\" %sccs.include.redist.man%
.\"
.\"
.\" %sccs.include.redist.man%
.\"
-.\" @(#)printf.3 6.14 (Berkeley) %G%
+.\" @(#)printf.3 6.15 (Berkeley) %G%
.Bl -bullet
.It
Zero or more of the following flags:
.Bl -bullet
.It
Zero or more of the following flags:
-.Bl -hyphen -offset indent
.Cm #
character
specifying that the value should be converted to an ``alternate form''.
.Cm #
character
specifying that the value should be converted to an ``alternate form''.
.Sq Cm +
character specifying that a sign always be placed before a
number produced by a signed conversion.
.Sq Cm +
character specifying that a sign always be placed before a
number produced by a signed conversion.
.Em long int
argument.
.It
.Em long int
argument.
.It
+The optional character
+.Cm q ,
+specifying that a following
+.Cm d ,
+.Cm i ,
+.Cm o ,
+.Cm u ,
+.Cm x ,
+or
+.Cm X
+conversion corresponds to a
+.Em quad int
+or
+.Em unsigned quad int
+argument, or that a following
+.Cm n
+conversion corresponds to a pointer to a
+.Em quad int
+argument.
+.It
The character
.Cm L
specifying that a following
The character
.Cm L
specifying that a following
*/
#if defined(LIBC_SCCS) && !defined(lint)
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vfprintf.c 5.48 (Berkeley) %G%";
+static char sccsid[] = "@(#)vfprintf.c 5.49 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
/*
#endif /* LIBC_SCCS and not lint */
/*
/*
* Flags used during conversion.
*/
/*
* Flags used during conversion.
*/
-#define LONGINT 0x01 /* long integer */
-#define LONGDBL 0x02 /* long double; unimplemented */
-#define SHORTINT 0x04 /* short integer */
-#define ALT 0x08 /* alternate form */
-#define LADJUST 0x10 /* left adjustment */
-#define ZEROPAD 0x20 /* zero (as opposed to blank) pad */
-#define HEXPREFIX 0x40 /* add 0x or 0X prefix */
+#define ALT 0x001 /* alternate form */
+#define HEXPREFIX 0x002 /* add 0x or 0X prefix */
+#define LADJUST 0x004 /* left adjustment */
+#define LONGDBL 0x008 /* long double; unimplemented */
+#define LONGINT 0x010 /* long integer */
+#define QUADINT 0x020 /* quad integer */
+#define SHORTINT 0x040 /* short integer */
+#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
int
vfprintf(fp, fmt0, ap)
FILE *fp;
const char *fmt0;
int
vfprintf(fp, fmt0, ap)
FILE *fp;
const char *fmt0;
-#if tahoe
- register /* technically illegal, since we do not know what type va_list is */
-#endif
va_list ap;
{
register char *fmt; /* format string */
va_list ap;
{
register char *fmt; /* format string */
double _double; /* double precision arguments %[eEfgG] */
int fpprec; /* `extra' floating precision in [eEfgG] */
#endif
double _double; /* double precision arguments %[eEfgG] */
int fpprec; /* `extra' floating precision in [eEfgG] */
#endif
- u_long _ulong; /* integer arguments %[diouxX] */
+ u_quad_t _uquad; /* integer arguments %[diouxX] */
enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
int dprec; /* a copy of prec if [diouxX], 0 otherwise */
int fieldsz; /* field size expanded by sign, etc */
enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
int dprec; /* a copy of prec if [diouxX], 0 otherwise */
int fieldsz; /* field size expanded by sign, etc */
char ox[2]; /* space for 0x hex-prefix */
/*
char ox[2]; /* space for 0x hex-prefix */
/*
- * Choose PADSIZE to trade efficiency vs size. If larger
- * printf fields occur frequently, increase PADSIZE (and make
- * the initialisers below longer).
+ * Choose PADSIZE to trade efficiency vs. size. If larger printf
+ * fields occur frequently, increase PADSIZE and make the initialisers
+ * below longer.
*/
#define PADSIZE 16 /* pad chunk size */
static char blanks[PADSIZE] =
*/
#define PADSIZE 16 /* pad chunk size */
static char blanks[PADSIZE] =
* argument extraction methods.
*/
#define SARG() \
* argument extraction methods.
*/
#define SARG() \
- (flags&LONGINT ? va_arg(ap, long) : \
+ (flags&QUADINT ? va_arg(ap, quad_t) : \
+ flags&LONGINT ? va_arg(ap, long) : \
flags&SHORTINT ? (long)(short)va_arg(ap, int) : \
(long)va_arg(ap, int))
#define UARG() \
flags&SHORTINT ? (long)(short)va_arg(ap, int) : \
(long)va_arg(ap, int))
#define UARG() \
- (flags&LONGINT ? va_arg(ap, u_long) : \
+ (flags&QUADINT ? va_arg(ap, u_quad_t) : \
+ flags&LONGINT ? va_arg(ap, u_long) : \
flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \
(u_long)va_arg(ap, u_int))
flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \
(u_long)va_arg(ap, u_int))
case 'l':
flags |= LONGINT;
goto rflag;
case 'l':
flags |= LONGINT;
goto rflag;
+ case 'q':
+ flags |= QUADINT;
+ goto rflag;
case 'c':
*(cp = buf) = va_arg(ap, int);
size = 1;
case 'c':
*(cp = buf) = va_arg(ap, int);
size = 1;
/*FALLTHROUGH*/
case 'd':
case 'i':
/*FALLTHROUGH*/
case 'd':
case 'i':
- _ulong = SARG();
- if ((long)_ulong < 0) {
- _ulong = -_ulong;
+ _uquad = SARG();
+ if ((quad_t)_uquad < 0) {
+ _uquad = -_uquad;
sign = '-';
}
base = DEC;
sign = '-';
}
base = DEC;
break;
#endif /* FLOATING_POINT */
case 'n':
break;
#endif /* FLOATING_POINT */
case 'n':
+ if (flags & QUADINT)
+ *va_arg(ap, quad_t *) = ret;
+ else if (flags & LONGINT)
*va_arg(ap, long *) = ret;
else if (flags & SHORTINT)
*va_arg(ap, short *) = ret;
*va_arg(ap, long *) = ret;
else if (flags & SHORTINT)
*va_arg(ap, short *) = ret;
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
base = OCT;
goto nosign;
case 'p':
base = OCT;
goto nosign;
case 'p':
* -- ANSI X3J11
*/
/* NOSTRICT */
* -- ANSI X3J11
*/
/* NOSTRICT */
- _ulong = (u_long)va_arg(ap, void *);
+ _uquad = (u_quad_t)va_arg(ap, void *);
base = HEX;
xdigs = "0123456789abcdef";
flags |= HEXPREFIX;
base = HEX;
xdigs = "0123456789abcdef";
flags |= HEXPREFIX;
flags |= LONGINT;
/*FALLTHROUGH*/
case 'u':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'u':
base = DEC;
goto nosign;
case 'X':
base = DEC;
goto nosign;
case 'X':
goto hex;
case 'x':
xdigs = "0123456789abcdef";
goto hex;
case 'x':
xdigs = "0123456789abcdef";
base = HEX;
/* leading 0x/X only if non-zero */
base = HEX;
/* leading 0x/X only if non-zero */
- if (flags & ALT && _ulong != 0)
+ if (flags & ALT && _uquad != 0)
flags |= HEXPREFIX;
/* unsigned conversions */
flags |= HEXPREFIX;
/* unsigned conversions */
* -- ANSI X3J11
*/
cp = buf + BUF;
* -- ANSI X3J11
*/
cp = buf + BUF;
- if (_ulong != 0 || prec != 0) {
+ if (_uquad != 0 || prec != 0) {
- * unsigned mod is hard, and unsigned mod
+ * Unsigned mod is hard, and unsigned mod
* by a constant is easier than that by
* a variable; hence this switch.
*/
switch (base) {
case OCT:
do {
* by a constant is easier than that by
* a variable; hence this switch.
*/
switch (base) {
case OCT:
do {
- *--cp = to_char(_ulong & 7);
- _ulong >>= 3;
- } while (_ulong);
+ *--cp = to_char(_uquad & 7);
+ _uquad >>= 3;
+ } while (_uquad);
/* handle octal leading 0 */
if (flags & ALT && *cp != '0')
*--cp = '0';
/* handle octal leading 0 */
if (flags & ALT && *cp != '0')
*--cp = '0';
case DEC:
/* many numbers are 1 digit */
case DEC:
/* many numbers are 1 digit */
- while (_ulong >= 10) {
- *--cp = to_char(_ulong % 10);
- _ulong /= 10;
+ while (_uquad >= 10) {
+ *--cp = to_char(_uquad % 10);
+ _uquad /= 10;
- *--cp = to_char(_ulong);
+ *--cp = to_char(_uquad);
- *--cp = xdigs[_ulong & 15];
- _ulong >>= 4;
- } while (_ulong);
+ *--cp = xdigs[_uquad & 15];
+ _uquad >>= 4;
+ } while (_uquad);