version 1.1.1.1, 2012/02/21 16:23:02
|
version 1.1.1.2, 2013/07/22 10:46:11
|
Line 1
|
Line 1
|
/* |
/* |
* Copyright (c) 1999-2005, 2008, 2010-2011 | * Copyright (c) 1999-2005, 2008, 2010-2013 |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* Copyright (c) 1990, 1993 |
* Copyright (c) 1990, 1993 |
* The Regents of the University of California. All rights reserved. |
* The Regents of the University of California. All rights reserved. |
Line 41
|
Line 41
|
|
|
#include <config.h> |
#include <config.h> |
|
|
|
#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_SNPRINTF) || !defined(HAVE_VASPRINTF) || !defined(HAVE_ASPRINTF) |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/param.h> |
|
|
|
#include <stdio.h> |
#include <stdio.h> |
#ifdef STDC_HEADERS |
#ifdef STDC_HEADERS |
Line 53
|
Line 54
|
# include <stdlib.h> |
# include <stdlib.h> |
# endif |
# endif |
#endif /* STDC_HEADERS */ |
#endif /* STDC_HEADERS */ |
#ifdef HAVE_STDINT_H | #if defined(HAVE_STDINT_H) |
# include <stdint.h> |
# include <stdint.h> |
|
#elif defined(HAVE_INTTYPES_H) |
|
# include <inttypes.h> |
#endif |
#endif |
#ifdef HAVE_STRING_H |
#ifdef HAVE_STRING_H |
# if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS) |
# if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS) |
Line 116 static int xxxprintf(char **, size_t, int, const char
|
Line 119 static int xxxprintf(char **, size_t, int, const char
|
#define LADJUST 0x004 /* left adjustment */ |
#define LADJUST 0x004 /* left adjustment */ |
#define LONGDBL 0x008 /* long double; unimplemented */ |
#define LONGDBL 0x008 /* long double; unimplemented */ |
#define LONGINT 0x010 /* long integer */ |
#define LONGINT 0x010 /* long integer */ |
#define QUADINT 0x020 /* quad integer */ | #define LLONGINT 0x020 /* quad integer */ |
#define SHORTINT 0x040 /* short integer */ |
#define SHORTINT 0x040 /* short integer */ |
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ |
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ |
|
|
Line 430 reswitch: switch (ch) {
|
Line 433 reswitch: switch (ch) {
|
flags |= SHORTINT; |
flags |= SHORTINT; |
goto rflag; |
goto rflag; |
case 'l': |
case 'l': |
flags |= LONGINT; | if (*fmt == 'l') { |
| fmt++; |
| flags |= LLONGINT; |
| } else { |
| flags |= LONGINT; |
| } |
goto rflag; |
goto rflag; |
#ifdef HAVE_LONG_LONG_INT |
#ifdef HAVE_LONG_LONG_INT |
case 'q': |
case 'q': |
flags |= QUADINT; | flags |= LLONGINT; |
goto rflag; |
goto rflag; |
#endif /* HAVE_LONG_LONG_INT */ |
#endif /* HAVE_LONG_LONG_INT */ |
case 'c': |
case 'c': |
Line 448 reswitch: switch (ch) {
|
Line 456 reswitch: switch (ch) {
|
case 'd': |
case 'd': |
case 'i': |
case 'i': |
#ifdef HAVE_LONG_LONG_INT |
#ifdef HAVE_LONG_LONG_INT |
if (flags & QUADINT) { | if (flags & LLONGINT) { |
uqval = va_arg(ap, long long); |
uqval = va_arg(ap, long long); |
if ((long long)uqval < 0) { |
if ((long long)uqval < 0) { |
uqval = -uqval; |
uqval = -uqval; |
Line 468 reswitch: switch (ch) {
|
Line 476 reswitch: switch (ch) {
|
goto number; |
goto number; |
case 'n': |
case 'n': |
#ifdef HAVE_LONG_LONG_INT |
#ifdef HAVE_LONG_LONG_INT |
if (flags & QUADINT) | if (flags & LLONGINT) |
*va_arg(ap, long long *) = ret; |
*va_arg(ap, long long *) = ret; |
else |
else |
#endif /* HAVE_LONG_LONG_INT */ |
#endif /* HAVE_LONG_LONG_INT */ |
Line 484 reswitch: switch (ch) {
|
Line 492 reswitch: switch (ch) {
|
/*FALLTHROUGH*/ |
/*FALLTHROUGH*/ |
case 'o': |
case 'o': |
#ifdef HAVE_LONG_LONG_INT |
#ifdef HAVE_LONG_LONG_INT |
if (flags & QUADINT) | if (flags & LLONGINT) |
uqval = va_arg(ap, unsigned long long); |
uqval = va_arg(ap, unsigned long long); |
else |
else |
#endif /* HAVE_LONG_LONG_INT */ |
#endif /* HAVE_LONG_LONG_INT */ |
Line 502 reswitch: switch (ch) {
|
Line 510 reswitch: switch (ch) {
|
ulval = (unsigned long)va_arg(ap, void *); |
ulval = (unsigned long)va_arg(ap, void *); |
base = 16; |
base = 16; |
xdigs = "0123456789abcdef"; |
xdigs = "0123456789abcdef"; |
flags = (flags & ~QUADINT) | HEXPREFIX; | flags = (flags & ~LLONGINT) | HEXPREFIX; |
ch = 'x'; |
ch = 'x'; |
goto nosign; |
goto nosign; |
case 's': |
case 's': |
Line 531 reswitch: switch (ch) {
|
Line 539 reswitch: switch (ch) {
|
/*FALLTHROUGH*/ |
/*FALLTHROUGH*/ |
case 'u': |
case 'u': |
#ifdef HAVE_LONG_LONG_INT |
#ifdef HAVE_LONG_LONG_INT |
if (flags & QUADINT) | if (flags & LLONGINT) |
uqval = va_arg(ap, unsigned long long); |
uqval = va_arg(ap, unsigned long long); |
else |
else |
#endif /* HAVE_LONG_LONG_INT */ |
#endif /* HAVE_LONG_LONG_INT */ |
Line 545 reswitch: switch (ch) {
|
Line 553 reswitch: switch (ch) {
|
xdigs = "0123456789abcdef"; |
xdigs = "0123456789abcdef"; |
hex: |
hex: |
#ifdef HAVE_LONG_LONG_INT |
#ifdef HAVE_LONG_LONG_INT |
if (flags & QUADINT) | if (flags & LLONGINT) |
uqval = va_arg(ap, unsigned long long); |
uqval = va_arg(ap, unsigned long long); |
else |
else |
#endif /* HAVE_LONG_LONG_INT */ |
#endif /* HAVE_LONG_LONG_INT */ |
Line 554 hex:
|
Line 562 hex:
|
/* leading 0x/X only if non-zero */ |
/* leading 0x/X only if non-zero */ |
if (flags & ALT && |
if (flags & ALT && |
#ifdef HAVE_LONG_LONG_INT |
#ifdef HAVE_LONG_LONG_INT |
(flags & QUADINT ? uqval != 0 : ulval != 0)) | (flags & LLONGINT ? uqval != 0 : ulval != 0)) |
#else |
#else |
ulval != 0) |
ulval != 0) |
#endif /* HAVE_LONG_LONG_INT */ |
#endif /* HAVE_LONG_LONG_INT */ |
Line 577 number: if ((dprec = prec) >= 0)
|
Line 585 number: if ((dprec = prec) >= 0)
|
*/ |
*/ |
cp = buf + BUF; |
cp = buf + BUF; |
#ifdef HAVE_LONG_LONG_INT |
#ifdef HAVE_LONG_LONG_INT |
if (flags & QUADINT) { | if (flags & LLONGINT) { |
if (uqval != 0 || prec != 0) |
if (uqval != 0 || prec != 0) |
cp = __uqtoa(uqval, cp, base, |
cp = __uqtoa(uqval, cp, base, |
flags & ALT, xdigs); |
flags & ALT, xdigs); |
Line 705 asprintf(char **str, char const *fmt, ...)
|
Line 713 asprintf(char **str, char const *fmt, ...)
|
return ret; |
return ret; |
} |
} |
#endif /* HAVE_ASPRINTF */ |
#endif /* HAVE_ASPRINTF */ |
|
|
|
#endif /* !HAVE_VSNPRINTF || !HAVE_SNPRINTF || !HAVE_VASPRINTF || !HAVE_ASPRINTF */ |