remove lib/isc/print.c and lib/isc/tests/print_test.c

This commit is contained in:
Mark Andrews
2018-05-18 14:00:08 +10:00
committed by Ondřej Surý
parent 7fc59e384c
commit 4c3386ad95
10 changed files with 11 additions and 1119 deletions

View File

@@ -180,6 +180,9 @@ char *getpassphrase(const char *);
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#if _MSC_VER < 1800
#error Use Visual Studio 2013 or later for %zu support.
#endif
#if _MSC_VER <= 1400
#define vsnprintf _vsnprintf
#endif

101
configure vendored
View File

@@ -731,12 +731,6 @@ ISC_PLATFORM_QUADFORMAT
DST_EXTRA_SRCS
DST_EXTRA_OBJS
USE_ISC_SPNEGO
ISC_EXTRA_SRCS
ISC_EXTRA_OBJS
ISC_PLATFORM_NEEDVSNPRINTF
ISC_PLATFORM_NEEDSPRINTF
ISC_PLATFORM_NEEDFPRINTF
ISC_PLATFORM_NEEDPRINTF
READLINE_LIB
ISC_PLATFORM_NEEDSTRCASESTR
ISC_PLATFORM_NEEDSTRLCAT
@@ -750,6 +744,8 @@ ISC_PLATFORM_HAVETFO
ISC_PLATFORM_NEEDPORTT
ISC_PLATFORM_MSGHDRFLAVOR
ISC_PLATFORM_HAVESALEN
ISC_EXTRA_SRCS
ISC_EXTRA_OBJS
ISC_PLATFORM_NEEDPTON
ISC_PLATFORM_NEEDNTOP
ISC_PLATFORM_HAVEIF_LADDRCONF
@@ -18431,6 +18427,8 @@ fi
#
# Look for a 4.4BSD-style sa_len member in struct sockaddr.
#
@@ -19022,97 +19020,6 @@ done
fi
ISC_PRINT_OBJS=
ISC_PRINT_SRCS=
ISC_PLATFORM_NEEDPRINTF='#undef ISC_PLATFORM_NEEDPRINTF'
ISC_PLATFORM_NEEDFPRINTF='#undef ISC_PLATFORM_NEEDFPRINTF'
ISC_PLATFORM_NEEDSPRINTF='#undef ISC_PLATFORM_NEEDSPRINTF'
ISC_PLATFORM_NEEDVSNPRINTF='#undef ISC_PLATFORM_NEEDVSNPRINTF'
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking sprintf return type" >&5
$as_echo_n "checking sprintf return type... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <stdio.h>
int
main ()
{
char buf[2]; return(*sprintf(buf,"x"));
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: char *" >&5
$as_echo "char *" >&6; }
ISC_PRINT_OBJS="print.$O"
ISC_PRINT_SRCS="print.c"
ISC_PLATFORM_NEEDSPRINTF="#define ISC_PLATFORM_NEEDSPRINTF"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: int" >&5
$as_echo "int" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_fn_c_check_func "$LINENO" "vsnprintf" "ac_cv_func_vsnprintf"
if test "x$ac_cv_func_vsnprintf" = xyes; then :
else
ISC_PRINT_OBJS="print.$O"
ISC_PRINT_SRCS="print.c"
ISC_PLATFORM_NEEDVSNPRINTF="#define ISC_PLATFORM_NEEDVSNPRINTF 1"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking printf for %z support" >&5
$as_echo_n "checking printf for %z support... " >&6; }
if test "$cross_compiling" = yes; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: assuming target platform supports %z" >&5
$as_echo "assuming target platform supports %z" >&6; }
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <stdio.h>
main() {
size_t j = 0;
char buf[100];
buf[0] = 0;
sprintf(buf, "%zu", j);
exit(strcmp(buf, "0") != 0);
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
ISC_PRINT_OBJS="print.$O"
ISC_PRINT_SRCS="print.c"
ISC_PLATFORM_NEEDPRINTF='#define ISC_PLATFORM_NEEDPRINTF 1'
ISC_PLATFORM_NEEDFPRINTF='#define ISC_PLATFORM_NEEDFPRINTF 1'
ISC_PLATFORM_NEEDFSRINTF='#define ISC_PLATFORM_NEEDSPRINTF 1'
ISC_PLATFORM_NEEDVSNPRINTF="#define ISC_PLATFORM_NEEDVSNPRINTF 1"
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
ISC_EXTRA_OBJS="$ISC_EXTRA_OBJS $ISC_PRINT_OBJS"
ISC_EXTRA_SRCS="$ISC_EXTRA_SRCS $ISC_PRINT_SRCS"
ac_fn_c_check_func "$LINENO" "strerror" "ac_cv_func_strerror"
if test "x$ac_cv_func_strerror" = xyes; then :

View File

@@ -2478,6 +2478,8 @@ main() { char a[16]; return (inet_pton(AF_INET, "1.2.3", a) == 1 ? 1 :
AC_SUBST(ISC_PLATFORM_NEEDNTOP)
AC_SUBST(ISC_PLATFORM_NEEDPTON)
AC_SUBST(ISC_EXTRA_OBJS)
AC_SUBST(ISC_EXTRA_SRCS)
#
# Look for a 4.4BSD-style sa_len member in struct sockaddr.
@@ -2777,59 +2779,6 @@ then
AC_CHECK_HEADERS(readline/history.h)
fi
ISC_PRINT_OBJS=
ISC_PRINT_SRCS=
ISC_PLATFORM_NEEDPRINTF='#undef ISC_PLATFORM_NEEDPRINTF'
ISC_PLATFORM_NEEDFPRINTF='#undef ISC_PLATFORM_NEEDFPRINTF'
ISC_PLATFORM_NEEDSPRINTF='#undef ISC_PLATFORM_NEEDSPRINTF'
ISC_PLATFORM_NEEDVSNPRINTF='#undef ISC_PLATFORM_NEEDVSNPRINTF'
AC_MSG_CHECKING(sprintf return type)
AC_TRY_COMPILE([
#include <stdio.h>
],
[ char buf[2]; return(*sprintf(buf,"x"));],
[AC_MSG_RESULT(char *)
ISC_PRINT_OBJS="print.$O"
ISC_PRINT_SRCS="print.c"
ISC_PLATFORM_NEEDSPRINTF="#define ISC_PLATFORM_NEEDSPRINTF"
],[AC_MSG_RESULT(int)])
AC_CHECK_FUNC(vsnprintf, [],
[ISC_PRINT_OBJS="print.$O"
ISC_PRINT_SRCS="print.c"
ISC_PLATFORM_NEEDVSNPRINTF="#define ISC_PLATFORM_NEEDVSNPRINTF 1"])
AC_MSG_CHECKING(printf for %z support)
AC_TRY_RUN([
#include <stdio.h>
main() {
size_t j = 0;
char buf[100];
buf[0] = 0;
sprintf(buf, "%zu", j);
exit(strcmp(buf, "0") != 0);
}
],
[AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)
ISC_PRINT_OBJS="print.$O"
ISC_PRINT_SRCS="print.c"
ISC_PLATFORM_NEEDPRINTF='#define ISC_PLATFORM_NEEDPRINTF 1'
ISC_PLATFORM_NEEDFPRINTF='#define ISC_PLATFORM_NEEDFPRINTF 1'
ISC_PLATFORM_NEEDFSRINTF='#define ISC_PLATFORM_NEEDSPRINTF 1'
ISC_PLATFORM_NEEDVSNPRINTF="#define ISC_PLATFORM_NEEDVSNPRINTF 1"],
[AC_MSG_RESULT(assuming target platform supports %z)])
AC_SUBST(ISC_PLATFORM_NEEDPRINTF)
AC_SUBST(ISC_PLATFORM_NEEDFPRINTF)
AC_SUBST(ISC_PLATFORM_NEEDSPRINTF)
AC_SUBST(ISC_PLATFORM_NEEDVSNPRINTF)
ISC_EXTRA_OBJS="$ISC_EXTRA_OBJS $ISC_PRINT_OBJS"
ISC_EXTRA_SRCS="$ISC_EXTRA_SRCS $ISC_PRINT_SRCS"
AC_SUBST(ISC_EXTRA_OBJS)
AC_SUBST(ISC_EXTRA_SRCS)
AC_CHECK_FUNC(strerror, AC_DEFINE(HAVE_STRERROR))
#

View File

@@ -165,27 +165,6 @@
*** Printing.
***/
/*! \brief
* If this system needs vsnprintf() and snprintf(), ISC_PLATFORM_NEEDVSNPRINTF
* will be defined.
*/
@ISC_PLATFORM_NEEDVSNPRINTF@
/*! \brief
* If this system need a modern sprintf() that returns (int) not (char*).
*/
@ISC_PLATFORM_NEEDSPRINTF@
/*! \brief
* If this system need a modern printf() that format size %z (size_t).
*/
@ISC_PLATFORM_NEEDPRINTF@
/*! \brief
* If this system need a modern fprintf() that format size %z (size_t).
*/
@ISC_PLATFORM_NEEDFPRINTF@
/*! \brief
* The printf format string modifier to use with isc_uint64_t values.
*/

View File

@@ -22,33 +22,6 @@
#include <isc/lang.h>
#include <isc/platform.h>
/*!
* This block allows lib/isc/print.c to be cleanly compiled even if
* the platform does not need it. The standard Makefile will still
* not compile print.c or archive print.o, so this is just to make test
* compilation ("make print.o") easier.
*/
#if !defined(ISC_PLATFORM_NEEDVSNPRINTF) && defined(ISC__PRINT_SOURCE)
#define ISC_PLATFORM_NEEDVSNPRINTF
#undef snprintf
#undef vsnprintf
#endif
#if !defined(ISC_PLATFORM_NEEDSPRINTF) && defined(ISC__PRINT_SOURCE)
#define ISC_PLATFORM_NEEDSPRINTF
#undef sprintf
#endif
#if !defined(ISC_PLATFORM_NEEDFPRINTF) && defined(ISC__PRINT_SOURCE)
#define ISC_PLATFORM_NEEDFPRINTF
#undef fprintf
#endif
#if !defined(ISC_PLATFORM_NEEDPRINTF) && defined(ISC__PRINT_SOURCE)
#define ISC_PLATFORM_NEEDPRINTF
#undef printf
#endif
/***
*** Macros
***/
@@ -58,50 +31,6 @@
*** Functions
***/
#ifdef ISC_PLATFORM_NEEDVSNPRINTF
#include <stdarg.h>
#include <stddef.h>
#endif
#include <stdio.h>
ISC_LANG_BEGINDECLS
#ifdef ISC_PLATFORM_NEEDVSNPRINTF
int
isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap)
ISC_FORMAT_PRINTF(3, 0);
#undef vsnprintf
#define vsnprintf isc_print_vsnprintf
int
isc_print_snprintf(char *str, size_t size, const char *format, ...)
ISC_FORMAT_PRINTF(3, 4);
#undef snprintf
#define snprintf isc_print_snprintf
#endif /* ISC_PLATFORM_NEEDVSNPRINTF */
#ifdef ISC_PLATFORM_NEEDSPRINTF
int
isc_print_sprintf(char *str, const char *format, ...) ISC_FORMAT_PRINTF(2, 3);
#undef sprintf
#define sprintf isc_print_sprintf
#endif
#ifdef ISC_PLATFORM_NEEDPRINTF
int
isc_print_printf(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
#undef printf
#define printf isc_print_printf
#endif
#ifdef ISC_PLATFORM_NEEDFPRINTF
int
isc_print_fprintf(FILE * fp, const char *format, ...) ISC_FORMAT_PRINTF(2, 3);
#undef fprintf
#define fprintf isc_print_fprintf
#endif
ISC_LANG_ENDDECLS
#endif /* ISC_PRINT_H */

View File

@@ -1,705 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
#include <config.h>
#include <ctype.h>
#include <stdio.h> /* for sprintf() */
#include <string.h> /* for strlen() */
#include <assert.h> /* for assert() */
#define ISC__PRINT_SOURCE /* Used to get the isc_print_* prototypes. */
#include <isc/assertions.h>
#include <isc/int.h>
#include <isc/msgs.h>
#include <isc/print.h>
#include <isc/stdlib.h>
#include <isc/util.h>
/*
* We use the system's sprintf so we undef it here.
*/
#undef sprintf
static int
isc__print_printf(void (*emit)(char, void *), void *arg,
const char *format, va_list ap);
static void
file_emit(char c, void *arg) {
FILE *fp = arg;
int i = c & 0xff;
putc(i, fp);
}
#if 0
static int
isc_print_vfprintf(FILE *fp, const char *format, va_list ap) {
assert(fp != NULL);
assert(format != NULL);
return (isc__print_printf(file_emit, fp, format, ap));
}
#endif
int
isc_print_printf(const char *format, ...) {
va_list ap;
int n;
assert(format != NULL);
va_start(ap, format);
n = isc__print_printf(file_emit, stdout, format, ap);
va_end(ap);
return (n);
}
int
isc_print_fprintf(FILE *fp, const char *format, ...) {
va_list ap;
int n;
assert(fp != NULL);
assert(format != NULL);
va_start(ap, format);
n = isc__print_printf(file_emit, fp, format, ap);
va_end(ap);
return (n);
}
static void
nocheck_emit(char c, void *arg) {
struct { char *str; } *a = arg;
*(a->str)++ = c;
}
int
isc_print_sprintf(char *str, const char *format, ...) {
struct { char *str; } arg;
int n;
va_list ap;
arg.str = str;
va_start(ap, format);
n = isc__print_printf(nocheck_emit, &arg, format, ap);
va_end(ap);
return (n);
}
/*!
* Return length of string that would have been written if not truncated.
*/
int
isc_print_snprintf(char *str, size_t size, const char *format, ...) {
va_list ap;
int ret;
va_start(ap, format);
ret = isc_print_vsnprintf(str, size, format, ap);
va_end(ap);
return (ret);
}
/*!
* Return length of string that would have been written if not truncated.
*/
static void
string_emit(char c, void *arg) {
struct { char *str; size_t size; } *p = arg;
if (p->size > 0U) {
*(p->str)++ = c;
p->size--;
}
}
int
isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) {
struct { char *str; size_t size; } arg;
int n;
assert(str != NULL);
assert(format != NULL);
arg.str = str;
arg.size = size;
n = isc__print_printf(string_emit, &arg, format, ap);
if (arg.size > 0U)
*arg.str = '\0';
return (n);
}
static int
isc__print_printf(void (*emit)(char, void *), void *arg,
const char *format, va_list ap)
{
int h;
int l;
int z;
int q;
int alt;
int zero;
int left;
int plus;
int space;
int neg;
isc_int64_t tmpi;
isc_uint64_t tmpui;
unsigned long width;
unsigned long precision;
unsigned int length;
char buf[1024];
char c;
void *v;
const char *cp;
const char *head;
int count = 0;
int pad;
int zeropad;
int dot;
double dbl;
isc_boolean_t precision_set;
#ifdef HAVE_LONG_DOUBLE
long double ldbl;
#endif
char fmt[32];
assert(emit != NULL);
assert(arg != NULL);
assert(format != NULL);
while (*format != '\0') {
if (*format != '%') {
emit(*format++, arg);
count++;
continue;
}
format++;
/*
* Reset flags.
*/
dot = neg = space = plus = left = zero = alt = h = l = q = z = 0;
width = precision = 0;
head = "";
pad = zeropad = 0;
precision_set = ISC_FALSE;
do {
if (*format == '#') {
alt = 1;
format++;
} else if (*format == '-') {
left = 1;
zero = 0;
format++;
} else if (*format == ' ') {
if (!plus)
space = 1;
format++;
} else if (*format == '+') {
plus = 1;
space = 0;
format++;
} else if (*format == '0') {
if (!left)
zero = 1;
format++;
} else
break;
} while (1);
/*
* Width.
*/
if (*format == '*') {
width = va_arg(ap, int);
format++;
} else if (isdigit((unsigned char)*format)) {
char *e;
width = strtoul(format, &e, 10);
format = e;
}
/*
* Precision.
*/
if (*format == '.') {
format++;
dot = 1;
if (*format == '*') {
precision = va_arg(ap, int);
precision_set = ISC_TRUE;
format++;
} else if (isdigit((unsigned char)*format)) {
char *e;
precision = strtoul(format, &e, 10);
precision_set = ISC_TRUE;
format = e;
}
}
switch (*format) {
case '\0':
continue;
case '%':
emit(*format, arg);
count++;
break;
case 'q':
q = 1;
format++;
goto doint;
case 'h':
h = 1;
format++;
goto doint;
case 'l':
l = 1;
format++;
if (*format == 'l') {
q = 1;
format++;
}
goto doint;
case 'z':
z = 1;
format++;
goto doint;
#ifdef WIN32
case 'I':
/* Windows has I64 as a modifier for a quad. */
if (format[1] == '6' && format[2] == '4') {
q = 1;
format += 3;
goto doint;
}
continue;
#endif
case 'n':
case 'i':
case 'd':
case 'o':
case 'u':
case 'x':
case 'X':
doint:
if (precision != 0U)
zero = 0;
switch (*format) {
case 'n':
if (h) {
short int *p;
p = va_arg(ap, short *);
assert(p != NULL);
*p = count;
} else if (l) {
long int *p;
p = va_arg(ap, long *);
assert(p != NULL);
*p = count;
} else if (z) {
size_t *p;
p = va_arg(ap, size_t *);
assert(p != NULL);
*p = count;
} else {
int *p;
p = va_arg(ap, int *);
assert(p != NULL);
*p = count;
}
break;
case 'i':
case 'd':
if (q)
tmpi = va_arg(ap, isc_int64_t);
else if (l)
tmpi = va_arg(ap, long int);
else if (z)
tmpi = va_arg(ap, ssize_t);
else
tmpi = va_arg(ap, int);
if (tmpi < 0) {
head = "-";
tmpui = -tmpi;
} else {
if (plus)
head = "+";
else if (space)
head = " ";
else
head = "";
tmpui = tmpi;
}
if (tmpui <= 0xffffffffU)
sprintf(buf, "%lu",
(unsigned long)tmpui);
else {
unsigned long mid;
unsigned long lo;
unsigned long hi;
lo = tmpui % 1000000000;
tmpui /= 1000000000;
mid = tmpui % 1000000000;
hi = tmpui / 1000000000;
if (hi != 0U) {
sprintf(buf, "%lu", hi);
sprintf(buf + strlen(buf),
"%09lu", mid);
} else
sprintf(buf, "%lu", mid);
sprintf(buf + strlen(buf), "%09lu",
lo);
}
goto printint;
case 'o':
if (q)
tmpui = va_arg(ap, isc_uint64_t);
else if (l)
tmpui = va_arg(ap, long int);
else if (z)
tmpui = va_arg(ap, size_t);
else
tmpui = va_arg(ap, int);
if (tmpui <= 0xffffffffU)
sprintf(buf, alt ? "%#lo" : "%lo",
(unsigned long)tmpui);
else {
unsigned long mid;
unsigned long lo;
unsigned long hi;
lo = tmpui % 010000000000;
tmpui /= 010000000000;
mid = tmpui % 010000000000;
hi = tmpui / 010000000000;
if (hi != 0U) {
sprintf(buf,
alt ? "%#lo" : "%lo",
hi);
sprintf(buf + strlen(buf),
"%09lo", mid);
} else
sprintf(buf,
alt ? "%#lo" : "%lo",
mid);
sprintf(buf + strlen(buf), "%09lo", lo);
}
goto printint;
case 'u':
if (q)
tmpui = va_arg(ap, isc_uint64_t);
else if (l)
tmpui = va_arg(ap, unsigned long int);
else if (z)
tmpui = va_arg(ap, size_t);
else
tmpui = va_arg(ap, unsigned int);
if (tmpui <= 0xffffffffU)
sprintf(buf, "%lu",
(unsigned long)tmpui);
else {
unsigned long mid;
unsigned long lo;
unsigned long hi;
lo = tmpui % 1000000000;
tmpui /= 1000000000;
mid = tmpui % 1000000000;
hi = tmpui / 1000000000;
if (hi != 0U) {
sprintf(buf, "%lu", hi);
sprintf(buf + strlen(buf),
"%09lu", mid);
} else
sprintf(buf, "%lu", mid);
sprintf(buf + strlen(buf), "%09lu",
lo);
}
goto printint;
case 'x':
if (q)
tmpui = va_arg(ap, isc_uint64_t);
else if (l)
tmpui = va_arg(ap, unsigned long int);
else if (z)
tmpui = va_arg(ap, size_t);
else
tmpui = va_arg(ap, unsigned int);
if (alt) {
head = "0x";
if (precision > 2U)
precision -= 2;
}
if (tmpui <= 0xffffffffU)
sprintf(buf, "%lx",
(unsigned long)tmpui);
else {
unsigned long hi = tmpui>>32;
unsigned long lo = tmpui & 0xffffffff;
sprintf(buf, "%lx", hi);
sprintf(buf + strlen(buf), "%08lx", lo);
}
goto printint;
case 'X':
if (q)
tmpui = va_arg(ap, isc_uint64_t);
else if (l)
tmpui = va_arg(ap, unsigned long int);
else if (z)
tmpui = va_arg(ap, size_t);
else
tmpui = va_arg(ap, unsigned int);
if (alt) {
head = "0X";
if (precision > 2U)
precision -= 2;
}
if (tmpui <= 0xffffffffU)
sprintf(buf, "%lX",
(unsigned long)tmpui);
else {
unsigned long hi = tmpui>>32;
unsigned long lo = tmpui & 0xffffffff;
sprintf(buf, "%lX", hi);
sprintf(buf + strlen(buf), "%08lX", lo);
}
goto printint;
printint:
if (precision_set || width != 0U) {
length = strlen(buf);
if (length < precision)
zeropad = precision - length;
else if (length < width && zero)
zeropad = width - length;
if (width != 0U) {
pad = width - length -
zeropad - strlen(head);
if (pad < 0)
pad = 0;
}
}
count += strlen(head) + strlen(buf) + pad +
zeropad;
if (!left) {
while (pad > 0) {
emit(' ', arg);
pad--;
}
}
cp = head;
while (*cp != '\0')
emit(*cp++, arg);
while (zeropad > 0) {
emit('0', arg);
zeropad--;
}
cp = buf;
while (*cp != '\0')
emit(*cp++, arg);
while (pad > 0) {
emit(' ', arg);
pad--;
}
break;
default:
break;
}
break;
case 's':
cp = va_arg(ap, char *);
if (precision_set) {
/*
* cp need not be NULL terminated.
*/
const char *tp;
unsigned long n;
if (precision != 0U)
assert(cp != NULL);
n = precision;
tp = cp;
while (n != 0U && *tp != '\0')
n--, tp++;
length = precision - n;
} else {
assert(cp != NULL);
length = strlen(cp);
}
if (width != 0U) {
pad = width - length;
if (pad < 0)
pad = 0;
}
count += pad + length;
if (!left)
while (pad > 0) {
emit(' ', arg);
pad--;
}
if (precision_set)
while (precision > 0U && *cp != '\0') {
emit(*cp++, arg);
precision--;
}
else
while (*cp != '\0')
emit(*cp++, arg);
while (pad > 0) {
emit(' ', arg);
pad--;
}
break;
case 'c':
c = va_arg(ap, int);
if (width > 0U) {
count += width;
width--;
if (left)
emit(c, arg);
while (width-- > 0U)
emit(' ', arg);
if (!left)
emit(c, arg);
} else {
count++;
emit(c, arg);
}
break;
case 'p':
v = va_arg(ap, void *);
sprintf(buf, "%p", v);
length = strlen(buf);
if (precision > length)
zeropad = precision - length;
if (width > 0U) {
pad = width - length - zeropad;
if (pad < 0)
pad = 0;
}
count += length + pad + zeropad;
if (!left)
while (pad > 0) {
emit(' ', arg);
pad--;
}
cp = buf;
if (zeropad > 0 && buf[0] == '0' &&
(buf[1] == 'x' || buf[1] == 'X')) {
emit(*cp++, arg);
emit(*cp++, arg);
while (zeropad > 0) {
emit('0', arg);
zeropad--;
}
}
while (*cp != '\0')
emit(*cp++, arg);
while (pad > 0) {
emit(' ', arg);
pad--;
}
break;
case 'D': /*deprecated*/
assert("use %ld instead of %D" == NULL);
case 'O': /*deprecated*/
assert("use %lo instead of %O" == NULL);
case 'U': /*deprecated*/
assert("use %lu instead of %U" == NULL);
case 'L':
#ifdef HAVE_LONG_DOUBLE
l = 1;
#else
assert("long doubles are not supported" == NULL);
#endif
/* FALLTHROUGH */
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
if (!dot)
precision = 6;
/*
* IEEE floating point.
* MIN 2.2250738585072014E-308
* MAX 1.7976931348623157E+308
* VAX floating point has a smaller range than IEEE.
*
* precisions > 324 don't make much sense.
* if we cap the precision at 512 we will not
* overflow buf.
*/
if (precision > 512U)
precision = 512;
sprintf(fmt, "%%%s%s.%lu%s%c", alt ? "#" : "",
plus ? "+" : space ? " " : "",
precision, l ? "L" : "", *format);
switch (*format) {
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
#ifdef HAVE_LONG_DOUBLE
if (l) {
ldbl = va_arg(ap, long double);
sprintf(buf, fmt, ldbl);
} else
#endif
{
dbl = va_arg(ap, double);
sprintf(buf, fmt, dbl);
}
length = strlen(buf);
if (width > 0U) {
pad = width - length;
if (pad < 0)
pad = 0;
}
count += length + pad;
if (!left)
while (pad > 0) {
emit(' ', arg);
pad--;
}
cp = buf;
while (*cp != ' ')
emit(*cp++, arg);
while (pad > 0) {
emit(' ', arg);
pad--;
}
break;
default:
continue;
}
break;
default:
continue;
}
format++;
}
return (count);
}

View File

@@ -17,7 +17,6 @@ tp: mem_test
tp: netaddr_test
tp: parse_test
tp: pool_test
tp: print_test
tp: queue_test
tp: radix_test
tp: regex_test

View File

@@ -16,7 +16,6 @@ atf_test_program{name='mem_test'}
atf_test_program{name='netaddr_test'}
atf_test_program{name='parse_test'}
atf_test_program{name='pool_test'}
atf_test_program{name='print_test'}
atf_test_program{name='queue_test'}
atf_test_program{name='radix_test'}
atf_test_program{name='regex_test'}

View File

@@ -35,7 +35,7 @@ SRCS = isctest.c aes_test.c atomic_test.c buffer_test.c \
counter_test.c errno_test.c file_test.c hash_test.c \
heap_test.c ht_test.c inet_ntop_test.c lex_test.c \
mem_test.c netaddr_test.c parse_test.c pool_test.c \
print_test.c queue_test.c radix_test.c random_test.c \
queue_test.c radix_test.c random_test.c \
regex_test.c result_test.c safe_test.c sockaddr_test.c \
socket_test.c socket_test.c symtab_test.c task_test.c \
taskpool_test.c time_test.c timer_test.c
@@ -46,7 +46,7 @@ TARGETS = aes_test@EXEEXT@ atomic_test@EXEEXT@ buffer_test@EXEEXT@ \
hash_test@EXEEXT@ heap_test@EXEEXT@ ht_test@EXEEXT@ \
inet_ntop_test@EXEEXT@ lex_test@EXEEXT@ mem_test@EXEEXT@ \
netaddr_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \
print_test@EXEEXT@ queue_test@EXEEXT@ radix_test@EXEEXT@ \
queue_test@EXEEXT@ radix_test@EXEEXT@ \
random_test@EXEEXT@ regex_test@EXEEXT@ result_test@EXEEXT@ \
safe_test@EXEEXT@ sockaddr_test@EXEEXT@ socket_test@EXEEXT@ \
socket_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \
@@ -115,11 +115,6 @@ pool_test@EXEEXT@: pool_test.@O@ isctest.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
pool_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
print_test.@O@: ${top_srcdir}/lib/isc/print.c
print_test@EXEEXT@: print_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
print_test.@O@ ${ISCLIBS} ${LIBS}
queue_test@EXEEXT@: queue_test.@O@ isctest.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
queue_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}

View File

@@ -1,163 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#include <config.h>
#include <atf-c.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
* Workout if we need to force the inclusion of print.c so we can test
* it on all platforms even if we don't include it in libisc.
*/
#include <isc/platform.h>
#if !defined(ISC_PLATFORM_NEEDPRINTF) && \
!defined(ISC_PLATFORM_NEEDFPRINTF) && \
!defined(ISC_PLATFORM_NEEDSPRINTF) && \
!defined(ISC_PLATFORM_NEEDVSNPRINTF)
#define ISC__PRINT_SOURCE
#include "../print.c"
#else
#if !defined(ISC_PLATFORM_NEEDPRINTF) || \
!defined(ISC_PLATFORM_NEEDFPRINTF) || \
!defined(ISC_PLATFORM_NEEDSPRINTF) || \
!defined(ISC_PLATFORM_NEEDVSNPRINTF)
#define ISC__PRINT_SOURCE
#endif
#include <isc/print.h>
#include <isc/types.h>
#include <isc/util.h>
#endif
ATF_TC(snprintf);
ATF_TC_HEAD(snprintf, tc) {
atf_tc_set_md_var(tc, "descr", "snprintf implementation");
}
ATF_TC_BODY(snprintf, tc) {
char buf[10000];
isc_uint64_t ll = 8589934592ULL;
isc_uint64_t nn = 20000000000000ULL;
isc_uint64_t zz = 10000000000000000000ULL;
int n;
size_t size;
UNUSED(tc);
/*
* 4294967296 <= 8589934592 < 1000000000^2 to verify fix for
* RT#36505.
*/
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%qu", ll);
ATF_CHECK_EQ(n, 10);
ATF_CHECK_STREQ(buf, "8589934592");
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%llu", ll);
ATF_CHECK_EQ(n, 10);
ATF_CHECK_STREQ(buf, "8589934592");
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%qu", nn);
ATF_CHECK_EQ(n, 14);
ATF_CHECK_STREQ(buf, "20000000000000");
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%llu", nn);
ATF_CHECK_EQ(n, 14);
ATF_CHECK_STREQ(buf, "20000000000000");
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%qu", zz);
ATF_CHECK_EQ(n, 20);
ATF_CHECK_STREQ(buf, "10000000000000000000");
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%llu", zz);
ATF_CHECK_EQ(n, 20);
ATF_CHECK_STREQ(buf, "10000000000000000000");
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%lld", nn);
ATF_CHECK_EQ(n, 14);
ATF_CHECK_STREQ(buf, "20000000000000");
size = 1000;
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%zu", size);
ATF_CHECK_EQ(n, 4);
ATF_CHECK_STREQ(buf, "1000");
size = 1000;
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%zx", size);
ATF_CHECK_EQ(n, 3);
ATF_CHECK_STREQ(buf, "3e8");
size = 1000;
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "%zo", size);
ATF_CHECK_EQ(n, 4);
ATF_CHECK_STREQ(buf, "1750");
zz = 0xf5f5f5f5f5f5f5f5ULL;
memset(buf, 0xff, sizeof(buf));
n = isc_print_snprintf(buf, sizeof(buf), "0x%"ISC_PRINT_QUADFORMAT"x", zz);
ATF_CHECK_EQ(n, 18);
ATF_CHECK_STREQ(buf, "0xf5f5f5f5f5f5f5f5");
}
ATF_TC(fprintf);
ATF_TC_HEAD(fprintf, tc) {
atf_tc_set_md_var(tc, "descr", "fprintf implementation");
}
ATF_TC_BODY(fprintf, tc) {
FILE *f;
int n;
size_t size;
char buf[10000];
UNUSED(tc);
f = fopen("fprintf.test", "w+");
ATF_REQUIRE(f != NULL);
size = 1000;
n = isc_print_fprintf(f, "%zu", size);
ATF_CHECK_EQ(n, 4);
rewind(f);
memset(buf, 0, sizeof(buf));
n = fread(buf, 1, sizeof(buf), f);
ATF_CHECK_EQ(n, 4);
fclose(f);
ATF_CHECK_STREQ(buf, "1000");
if ((n > 0) && (!strcmp(buf, "1000")))
unlink("fprintf.test");
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, snprintf);
ATF_TP_ADD_TC(tp, fprintf);
return (atf_no_error());
}