--- /dev/null
+/* 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 */
case "${host}" in
- *-*-cygwin*)
+ *-*-cygwin*)
cat >> confdefs.h <<\EOF
#define HAVE_SYS_ERRLIST 1
EOF
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
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. */
; 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
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*
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. */
; 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
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
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.
#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
}
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
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
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.
}
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