merge from gcc

This commit is contained in:
DJ Delorie 2001-11-28 02:11:49 +00:00
parent c0851fd2d2
commit 24acd898d2
5 changed files with 413 additions and 46 deletions

View File

@ -1,3 +1,11 @@
2001-11-27 Zack Weinberg <zack@codesourcery.com>
* _doprnt.c: Moved here from gcc/doprint.c. Adjust to build
in libiberty context. Fix typo in leading comment.
* configure.in: Fix various AC_DEFINEs so autoheader works.
If any of vprintf, vsprintf, vfprintf is missing from libc,
then AC_REPLACE_FUNCS(_doprnt).
2001-11-26 DJ Delorie <dj@redhat.com>
Daniel Jacobowitz <drow@mvista.com>

296
libiberty/_doprnt.c Normal file
View File

@ -0,0 +1,296 @@
/* Provide a version of _doprnt in terms of fprintf.
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
Contributed by Kaveh Ghazi (ghazi@caip.rutgers.edu) 3/29/98
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "config.h"
#include "ansidecl.h"
#include "safe-ctype.h"
#include <stdio.h>
#ifdef ANSI_PROTOTYPES
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#undef _doprnt
#ifdef TEST /* Make sure to use the internal one. */
#define _doprnt my_doprnt
#endif
#define COPY_VA_INT \
do { \
const int value = abs (va_arg (ap, int)); \
char buf[32]; \
ptr++; /* Go past the asterisk. */ \
*sptr = '\0'; /* NULL terminate sptr. */ \
sprintf(buf, "%d", value); \
strcat(sptr, buf); \
while (*sptr) sptr++; \
} while (0)
#define PRINT_CHAR(CHAR) \
do { \
putc(CHAR, stream); \
ptr++; \
total_printed++; \
continue; \
} while (0)
#define PRINT_TYPE(TYPE) \
do { \
int result; \
TYPE value = va_arg (ap, TYPE); \
*sptr++ = *ptr++; /* Copy the type specifier. */ \
*sptr = '\0'; /* NULL terminate sptr. */ \
result = fprintf(stream, specifier, value); \
if (result == -1) \
return -1; \
else \
{ \
total_printed += result; \
continue; \
} \
} while (0)
int
_doprnt (format, ap, stream)
const char * format;
va_list ap;
FILE * stream;
{
const char * ptr = format;
char specifier[128];
int total_printed = 0;
while (*ptr != '\0')
{
if (*ptr != '%') /* While we have regular characters, print them. */
PRINT_CHAR(*ptr);
else /* We got a format specifier! */
{
char * sptr = specifier;
int wide_width = 0, short_width = 0;
*sptr++ = *ptr++; /* Copy the % and move forward. */
while (strchr ("-+ #0", *ptr)) /* Move past flags. */
*sptr++ = *ptr++;
if (*ptr == '*')
COPY_VA_INT;
else
while (ISDIGIT(*ptr)) /* Handle explicit numeric value. */
*sptr++ = *ptr++;
if (*ptr == '.')
{
*sptr++ = *ptr++; /* Copy and go past the period. */
if (*ptr == '*')
COPY_VA_INT;
else
while (ISDIGIT(*ptr)) /* Handle explicit numeric value. */
*sptr++ = *ptr++;
}
while (strchr ("hlL", *ptr))
{
switch (*ptr)
{
case 'h':
short_width = 1;
break;
case 'l':
wide_width++;
break;
case 'L':
wide_width = 2;
break;
default:
abort();
}
*sptr++ = *ptr++;
}
switch (*ptr)
{
case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
case 'c':
{
/* Short values are promoted to int, so just copy it
as an int and trust the C library printf to cast it
to the right width. */
if (short_width)
PRINT_TYPE(int);
else
{
switch (wide_width)
{
case 0:
PRINT_TYPE(int);
break;
case 1:
PRINT_TYPE(long);
break;
case 2:
default:
#if defined(__GNUC__) || defined(HAVE_LONG_LONG)
PRINT_TYPE(long long);
#else
PRINT_TYPE(long); /* Fake it and hope for the best. */
#endif
break;
} /* End of switch (wide_width) */
} /* End of else statement */
} /* End of integer case */
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
{
if (wide_width == 0)
PRINT_TYPE(double);
else
{
#if defined(__GNUC__) || defined(HAVE_LONG_DOUBLE)
PRINT_TYPE(long double);
#else
PRINT_TYPE(double); /* Fake it and hope for the best. */
#endif
}
}
break;
case 's':
PRINT_TYPE(char *);
break;
case 'p':
PRINT_TYPE(void *);
break;
case '%':
PRINT_CHAR('%');
break;
default:
abort();
} /* End of switch (*ptr) */
} /* End of else statement */
}
return total_printed;
}
#ifdef TEST
#include <math.h>
#ifndef M_PI
#define M_PI (3.1415926535897932385)
#endif
#define RESULT(x) do \
{ \
int i = (x); \
printf ("printed %d characters\n", i); \
fflush(stdin); \
} while (0)
static int checkit PARAMS ((const char * format, ...)) ATTRIBUTE_PRINTF_1;
static int
checkit VPARAMS ((const char* format, ...))
{
int result;
VA_OPEN (args, format);
VA_FIXEDARG (args, char *, format);
result = _doprnt (format, args, stdout);
VA_CLOSE (args);
return result;
}
int
main ()
{
RESULT(checkit ("<%d>\n", 0x12345678));
RESULT(printf ("<%d>\n", 0x12345678));
RESULT(checkit ("<%200d>\n", 5));
RESULT(printf ("<%200d>\n", 5));
RESULT(checkit ("<%.300d>\n", 6));
RESULT(printf ("<%.300d>\n", 6));
RESULT(checkit ("<%100.150d>\n", 7));
RESULT(printf ("<%100.150d>\n", 7));
RESULT(checkit ("<%s>\n",
"jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\
777777777777777777333333333333366666666666622222222222777777777777733333"));
RESULT(printf ("<%s>\n",
"jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\
777777777777777777333333333333366666666666622222222222777777777777733333"));
RESULT(checkit ("<%f><%0+#f>%s%d%s>\n",
1.0, 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"));
RESULT(printf ("<%f><%0+#f>%s%d%s>\n",
1.0, 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"));
RESULT(checkit ("<%4f><%.4f><%%><%4.4f>\n", M_PI, M_PI, M_PI));
RESULT(printf ("<%4f><%.4f><%%><%4.4f>\n", M_PI, M_PI, M_PI));
RESULT(checkit ("<%*f><%.*f><%%><%*.*f>\n", 3, M_PI, 3, M_PI, 3, 3, M_PI));
RESULT(printf ("<%*f><%.*f><%%><%*.*f>\n", 3, M_PI, 3, M_PI, 3, 3, M_PI));
RESULT(checkit ("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(printf ("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(checkit ("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(printf ("<%d><%i><%o><%u><%x><%X><%c>\n",
75, 75, 75, 75, 75, 75, 75));
RESULT(checkit ("Testing (hd) short: <%d><%ld><%hd><%hd><%d>\n", 123, (long)234, 345, 123456789, 456));
RESULT(printf ("Testing (hd) short: <%d><%ld><%hd><%hd><%d>\n", 123, (long)234, 345, 123456789, 456));
#if defined(__GNUC__) || defined (HAVE_LONG_LONG)
RESULT(checkit ("Testing (lld) long long: <%d><%lld><%d>\n", 123, 234234234234234234LL, 345));
RESULT(printf ("Testing (lld) long long: <%d><%lld><%d>\n", 123, 234234234234234234LL, 345));
RESULT(checkit ("Testing (Ld) long long: <%d><%Ld><%d>\n", 123, 234234234234234234LL, 345));
RESULT(printf ("Testing (Ld) long long: <%d><%Ld><%d>\n", 123, 234234234234234234LL, 345));
#endif
#if defined(__GNUC__) || defined (HAVE_LONG_DOUBLE)
RESULT(checkit ("Testing (Lf) long double: <%.20f><%.20Lf><%0+#.20f>\n",
1.23456, 1.234567890123456789L, 1.23456));
RESULT(printf ("Testing (Lf) long double: <%.20f><%.20Lf><%0+#.20f>\n",
1.23456, 1.234567890123456789L, 1.23456));
#endif
return 0;
}
#endif /* TEST */

View File

@ -1,4 +1,4 @@
/* config.in. Generated automatically from configure.in by autoheader. */
/* config.in. Generated automatically from configure.in by autoheader 2.13. */
/* Define to empty if the keyword does not work. */
#undef const
@ -30,8 +30,8 @@
/* Define vfork as fork if vfork does not work. */
#undef vfork
/* Define if the system defines a uintptr_t type. */
#undef HAVE_UINTPTR_T
/* Define if you have the _doprnt function. */
#undef HAVE__DOPRNT
/* Define if you have the asprintf function. */
#undef HAVE_ASPRINTF
@ -60,6 +60,9 @@
/* Define if you have the clock function. */
#undef HAVE_CLOCK
/* Define if you have the ffs function. */
#undef HAVE_FFS
/* Define if you have the getcwd function. */
#undef HAVE_GETCWD
@ -180,12 +183,12 @@
/* Define if you have the waitpid function. */
#undef HAVE_WAITPID
/* Define if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define if you have the <alloca.h> header file. */
#undef HAVE_ALLOCA_H
/* Define if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
@ -225,6 +228,9 @@
/* Define if errno must be declared even when <errno.h> is included. */
#undef NEED_DECLARATION_ERRNO
/* Define if you have the `uintptr_t' type. */
#undef HAVE_UINTPTR_T
/* Define if you have the sys_errlist variable. */
#undef HAVE_SYS_ERRLIST

122
libiberty/configure vendored
View File

@ -1965,7 +1965,7 @@ fi
case "${host}" in
*-*-cygwin*)
*-*-cygwin*)
cat >> confdefs.h <<\EOF
#define HAVE_SYS_ERRLIST 1
EOF
@ -2653,21 +2653,84 @@ fi
if test $ac_cv_func_vfork_works = no; then
LIBOBJS="$LIBOBJS vfork.o"
fi
# We only need _doprnt if we might use it to implement v*printf.
if test $ac_cv_func_vprintf != yes \
|| test $ac_cv_func_vfprintf != yes \
|| test $ac_cv_func_vsprintf != yes; then
for ac_func in _doprnt
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:2664: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 2669 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
#include <assert.h>
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char $ac_func();
int main() {
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
choke me
#else
$ac_func();
#endif
; return 0; }
EOF
if { (eval echo configure:2692: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
echo "configure: failed program was:" >&5
cat conftest.$ac_ext >&5
rm -rf conftest*
eval "ac_cv_func_$ac_func=no"
fi
rm -f conftest*
fi
if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
echo "$ac_t""yes" 1>&6
ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
cat >> confdefs.h <<EOF
#define $ac_tr_func 1
EOF
else
echo "$ac_t""no" 1>&6
LIBOBJS="$LIBOBJS ${ac_func}.${ac_objext}"
fi
done
fi
for v in $vars; do
echo $ac_n "checking for $v""... $ac_c" 1>&6
echo "configure:2659: checking for $v" >&5
echo "configure:2722: checking for $v" >&5
if eval "test \"`echo '$''{'libiberty_cv_var_$v'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 2664 "configure"
#line 2727 "configure"
#include "confdefs.h"
int *p;
int main() {
extern int $v; p = &$v;
; return 0; }
EOF
if { (eval echo configure:2671: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
if { (eval echo configure:2734: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "libiberty_cv_var_$v=yes"
else
@ -2693,12 +2756,12 @@ EOF
for ac_func in $checkfuncs
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:2697: checking for $ac_func" >&5
echo "configure:2760: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 2702 "configure"
#line 2765 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@ -2721,7 +2784,7 @@ $ac_func();
; return 0; }
EOF
if { (eval echo configure:2725: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
if { (eval echo configure:2788: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
@ -2747,21 +2810,21 @@ done
fi
for ac_hdr in stdlib.h unistd.h sys/stat.h sys/types.h
for ac_hdr in unistd.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
echo "configure:2755: checking for $ac_hdr" >&5
echo "configure:2818: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 2760 "configure"
#line 2823 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:2765: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
{ (eval echo configure:2828: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
@ -2790,12 +2853,12 @@ done
for ac_func in getpagesize
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:2794: checking for $ac_func" >&5
echo "configure:2857: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 2799 "configure"
#line 2862 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@ -2818,7 +2881,7 @@ $ac_func();
; return 0; }
EOF
if { (eval echo configure:2822: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
if { (eval echo configure:2885: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
@ -2843,7 +2906,7 @@ fi
done
echo $ac_n "checking for working mmap""... $ac_c" 1>&6
echo "configure:2847: checking for working mmap" >&5
echo "configure:2910: checking for working mmap" >&5
if eval "test \"`echo '$''{'ac_cv_func_mmap_fixed_mapped'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@ -2851,7 +2914,7 @@ else
ac_cv_func_mmap_fixed_mapped=no
else
cat > conftest.$ac_ext <<EOF
#line 2855 "configure"
#line 2918 "configure"
#include "confdefs.h"
/* Thanks to Mike Haertel and Jim Avera for this test.
@ -2879,24 +2942,11 @@ else
#include <fcntl.h>
#include <sys/mman.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
/* This mess was copied from the GNU getpagesize.h. */
#ifndef HAVE_GETPAGESIZE
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
/* Assume that all systems that can run configure have sys/param.h. */
# ifndef HAVE_SYS_PARAM_H
@ -3004,7 +3054,7 @@ main()
}
EOF
if { (eval echo configure:3008: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:3058: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_func_mmap_fixed_mapped=yes
else
@ -3028,7 +3078,7 @@ fi
echo $ac_n "checking for working strncmp""... $ac_c" 1>&6
echo "configure:3032: checking for working strncmp" >&5
echo "configure:3082: checking for working strncmp" >&5
if eval "test \"`echo '$''{'ac_cv_func_strncmp_works'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@ -3036,7 +3086,7 @@ else
ac_cv_func_strncmp_works=no
else
cat > conftest.$ac_ext <<EOF
#line 3040 "configure"
#line 3090 "configure"
#include "confdefs.h"
/* Test by Jim Wilson and Kaveh Ghazi.
@ -3097,7 +3147,7 @@ main ()
}
EOF
if { (eval echo configure:3101: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:3151: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_func_strncmp_works=yes
else

View File

@ -132,7 +132,7 @@ AC_EGREP_HEADER(uintptr_t, sys/types.h,
if test $libiberty_cv_uintptr_t = yes
then
AC_DEFINE(HAVE_UINTPTR_T)
AC_DEFINE(HAVE_UINTPTR_T, 1, [Define if you have the \`uintptr_t' type.])
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
@ -254,9 +254,9 @@ fi
AC_SUBST(CHECK)
case "${host}" in
*-*-cygwin*)
AC_DEFINE(HAVE_SYS_ERRLIST)
AC_DEFINE(HAVE_SYS_NERR)
*-*-cygwin*)
AC_DEFINE_NOAUTOHEADER(HAVE_SYS_ERRLIST)
AC_DEFINE_NOAUTOHEADER(HAVE_SYS_NERR)
;;
esac
@ -351,6 +351,13 @@ if test -z "${setobjs}"; then
if test $ac_cv_func_vfork_works = no; then
LIBOBJS="$LIBOBJS vfork.o"
fi
# We only need _doprnt if we might use it to implement v*printf.
if test $ac_cv_func_vprintf != yes \
|| test $ac_cv_func_vfprintf != yes \
|| test $ac_cv_func_vsprintf != yes; then
AC_REPLACE_FUNCS(_doprnt)
fi
for v in $vars; do
AC_MSG_CHECKING([for $v])
AC_CACHE_VAL(libiberty_cv_var_$v,