summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libiberty/ChangeLog11
-rw-r--r--libiberty/Makefile.in14
-rw-r--r--libiberty/config.in6
-rwxr-xr-xlibiberty/configure160
-rw-r--r--libiberty/configure.in4
-rw-r--r--libiberty/functions.texi26
-rw-r--r--libiberty/snprintf.c65
-rw-r--r--libiberty/vsnprintf.c149
8 files changed, 349 insertions, 86 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 1e290a559a1..027fe91c0f1 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,14 @@
+2003-04-16 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * configure.in (funcs, AC_CHECK_FUNCS): Add snprintf and
+ vsnprintf.
+ * snprintf.c, vsnprintf.c: New files.
+ * Makefile.in (CFILES): Add snprintf.c and vsnprintf.c.
+ (CONFIGURED_OFILES): Add snprintf.o and vsnprintf.o.
+ Regenerate dependencies.
+
+ * functions.texi, configure, config.in: Regenerated.
+
2003-04-15 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* mempcpy.c, stpcpy.c, stpncpy.c: New files.
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index af512a2b1fa..d73ab2fef77 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -147,12 +147,12 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \
pex-unix.c pex-win32.c \
physmem.c putenv.c \
random.c regex.c rename.c rindex.c \
- safe-ctype.c setenv.c sigsetmask.c sort.c spaces.c \
+ safe-ctype.c setenv.c sigsetmask.c snprintf.c sort.c spaces.c \
splay-tree.c stpcpy.c stpncpy.c strcasecmp.c strchr.c strdup.c \
strerror.c strncasecmp.c strncmp.c strrchr.c strsignal.c \
strstr.c strtod.c strtol.c strtoul.c \
ternary.c tmpnam.c \
- vasprintf.c vfork.c vfprintf.c vprintf.c vsprintf.c \
+ vasprintf.c vfork.c vfprintf.c vprintf.c vsnprintf.c vsprintf.c \
waitpid.c \
xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c
@@ -191,11 +191,11 @@ CONFIGURED_OFILES = asprintf.o atexit.o \
pex-unix.o pex-win32.o \
putenv.o \
random.o rename.o rindex.o \
- setenv.o sigsetmask.o stpcpy.o stpncpy.o strcasecmp.o strchr.o \
- strdup.o strncasecmp.o strncmp.o strrchr.o strstr.o strtod.o \
- strtol.o strtoul.o \
+ setenv.o sigsetmask.o snprintf.o stpcpy.o stpncpy.o strcasecmp.o \
+ strchr.o strdup.o strncasecmp.o strncmp.o strrchr.o strstr.o \
+ strtod.o strtol.o strtoul.o \
tmpnam.o \
- vasprintf.o vfork.o vfprintf.o vprintf.o vsprintf.o \
+ vasprintf.o vfork.o vfprintf.o vprintf.o vsnprintf.o vsprintf.o \
waitpid.o
# These files are installed if the library has been configured to do so.
@@ -486,6 +486,7 @@ rename.o: config.h $(INCDIR)/ansidecl.h
safe-ctype.o: $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h
setenv.o: config.h $(INCDIR)/ansidecl.h
sigsetmask.o: $(INCDIR)/ansidecl.h
+snprintf.o: $(INCDIR)/ansidecl.h
sort.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
$(INCDIR)/sort.h
spaces.o: $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
@@ -510,6 +511,7 @@ vasprintf.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
vfork.o: $(INCDIR)/ansidecl.h
vfprintf.o: $(INCDIR)/ansidecl.h
vprintf.o: $(INCDIR)/ansidecl.h
+vsnprintf.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
vsprintf.o: $(INCDIR)/ansidecl.h
waitpid.o: config.h
xatexit.o: $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
diff --git a/libiberty/config.in b/libiberty/config.in
index 0efae6d901e..1cc6d6132e5 100644
--- a/libiberty/config.in
+++ b/libiberty/config.in
@@ -150,6 +150,9 @@
/* Define if you have the sigsetmask function. */
#undef HAVE_SIGSETMASK
+/* Define if you have the snprintf function. */
+#undef HAVE_SNPRINTF
+
/* Define if you have the stpcpy function. */
#undef HAVE_STPCPY
@@ -216,6 +219,9 @@
/* Define if you have the vprintf function. */
#undef HAVE_VPRINTF
+/* Define if you have the vsnprintf function. */
+#undef HAVE_VSNPRINTF
+
/* Define if you have the vsprintf function. */
#undef HAVE_VSPRINTF
diff --git a/libiberty/configure b/libiberty/configure
index ed8b3886625..f1ba0c85832 100755
--- a/libiberty/configure
+++ b/libiberty/configure
@@ -1716,6 +1716,7 @@ funcs="$funcs random"
funcs="$funcs rename"
funcs="$funcs rindex"
funcs="$funcs setenv"
+funcs="$funcs snprintf"
funcs="$funcs sigsetmask"
funcs="$funcs stpcpy"
funcs="$funcs stpncpy"
@@ -1732,6 +1733,7 @@ funcs="$funcs tmpnam"
funcs="$funcs vasprintf"
funcs="$funcs vfprintf"
funcs="$funcs vprintf"
+funcs="$funcs vsnprintf"
funcs="$funcs vsprintf"
funcs="$funcs waitpid"
@@ -1749,12 +1751,12 @@ if test "x" = "y"; then
for ac_func in asprintf atexit basename bcmp bcopy bsearch bzero calloc clock
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1753: checking for $ac_func" >&5
+echo "configure:1755: 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 1758 "configure"
+#line 1760 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -1777,7 +1779,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:1781: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1783: \"$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
@@ -1804,12 +1806,12 @@ done
for ac_func in getcwd getpagesize index insque mkstemps memchr memcmp memcpy
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1808: checking for $ac_func" >&5
+echo "configure:1810: 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 1813 "configure"
+#line 1815 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -1832,7 +1834,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:1836: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1838: \"$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
@@ -1859,12 +1861,12 @@ done
for ac_func in memmove mempcpy memset putenv random rename rindex sigsetmask
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1863: checking for $ac_func" >&5
+echo "configure:1865: 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 1868 "configure"
+#line 1870 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -1887,7 +1889,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:1891: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1893: \"$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
@@ -1914,12 +1916,12 @@ done
for ac_func in strcasecmp setenv stpcpy stpncpy strchr strdup strncasecmp strrchr strstr
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1918: checking for $ac_func" >&5
+echo "configure:1920: 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 1923 "configure"
+#line 1925 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -1942,7 +1944,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:1946: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1948: \"$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
@@ -1969,12 +1971,12 @@ done
for ac_func in strtod strtol strtoul tmpnam vasprintf vfprintf vprintf
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1973: checking for $ac_func" >&5
+echo "configure:1975: 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 1978 "configure"
+#line 1980 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -1997,7 +1999,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:2001: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2003: \"$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
@@ -2024,12 +2026,12 @@ done
for ac_func in vsprintf waitpid getrusage on_exit psignal strerror strsignal
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2028: checking for $ac_func" >&5
+echo "configure:2030: 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 2033 "configure"
+#line 2035 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -2052,7 +2054,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:2056: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2058: \"$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
@@ -2076,15 +2078,15 @@ else
fi
done
- for ac_func in sysconf times sbrk gettimeofday ffs
+ for ac_func in sysconf times sbrk gettimeofday ffs snprintf vsnprintf
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2083: checking for $ac_func" >&5
+echo "configure:2085: 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 2088 "configure"
+#line 2090 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -2107,7 +2109,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:2111: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2113: \"$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
@@ -2134,12 +2136,12 @@ done
for ac_func in pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2138: checking for $ac_func" >&5
+echo "configure:2140: 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 2143 "configure"
+#line 2145 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -2162,7 +2164,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:2166: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2168: \"$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
@@ -2189,12 +2191,12 @@ done
for ac_func in realpath canonicalize_file_name
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2193: checking for $ac_func" >&5
+echo "configure:2195: 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 2198 "configure"
+#line 2200 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -2217,7 +2219,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:2221: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2223: \"$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
@@ -2451,7 +2453,7 @@ if test -z "${setobjs}"; then
# We haven't set the list of objects yet. Use the standard autoconf
# tests. This will only work if the compiler works.
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:2455: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:2457: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
ac_ext=c
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
@@ -2462,12 +2464,12 @@ cross_compiling=$ac_cv_prog_cc_cross
cat > conftest.$ac_ext << EOF
-#line 2466 "configure"
+#line 2468 "configure"
#include "confdefs.h"
main(){return(0);}
EOF
-if { (eval echo configure:2471: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2473: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
ac_cv_prog_cc_works=yes
# If we can't run a trivial program, we are probably using a cross compiler.
if (./conftest; exit) 2>/dev/null; then
@@ -2493,19 +2495,19 @@ if test $ac_cv_prog_cc_works = no; then
{ echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
fi
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:2497: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:2499: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
cross_compiling=$ac_cv_prog_cc_cross
for ac_func in $funcs
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2504: checking for $ac_func" >&5
+echo "configure:2506: 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 2509 "configure"
+#line 2511 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -2528,7 +2530,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:2532: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2534: \"$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
@@ -2555,12 +2557,12 @@ done
echo $ac_n "checking whether alloca needs Cray hooks""... $ac_c" 1>&6
-echo "configure:2559: checking whether alloca needs Cray hooks" >&5
+echo "configure:2561: checking whether alloca needs Cray hooks" >&5
if eval "test \"`echo '$''{'ac_cv_os_cray'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 2564 "configure"
+#line 2566 "configure"
#include "confdefs.h"
#if defined(CRAY) && ! defined(CRAY2)
webecray
@@ -2585,12 +2587,12 @@ echo "$ac_t""$ac_cv_os_cray" 1>&6
if test $ac_cv_os_cray = yes; then
for ac_func in _getb67 GETB67 getb67; do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2589: checking for $ac_func" >&5
+echo "configure:2591: 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 2594 "configure"
+#line 2596 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -2613,7 +2615,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:2617: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2619: \"$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
@@ -2639,7 +2641,7 @@ fi
fi
echo $ac_n "checking stack direction for C alloca""... $ac_c" 1>&6
-echo "configure:2643: checking stack direction for C alloca" >&5
+echo "configure:2645: checking stack direction for C alloca" >&5
if eval "test \"`echo '$''{'ac_cv_c_stack_direction'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -2647,7 +2649,7 @@ else
ac_cv_c_stack_direction=0
else
cat > conftest.$ac_ext <<EOF
-#line 2651 "configure"
+#line 2653 "configure"
#include "confdefs.h"
find_stack_direction ()
{
@@ -2666,7 +2668,7 @@ main ()
exit (find_stack_direction() < 0);
}
EOF
-if { (eval echo configure:2670: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2672: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_c_stack_direction=1
else
@@ -2688,17 +2690,17 @@ EOF
ac_safe=`echo "vfork.h" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for vfork.h""... $ac_c" 1>&6
-echo "configure:2692: checking for vfork.h" >&5
+echo "configure:2694: checking for vfork.h" >&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 2697 "configure"
+#line 2699 "configure"
#include "confdefs.h"
#include <vfork.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2702: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2704: \"$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*
@@ -2723,18 +2725,18 @@ else
fi
echo $ac_n "checking for working vfork""... $ac_c" 1>&6
-echo "configure:2727: checking for working vfork" >&5
+echo "configure:2729: checking for working vfork" >&5
if eval "test \"`echo '$''{'ac_cv_func_vfork_works'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test "$cross_compiling" = yes; then
echo $ac_n "checking for vfork""... $ac_c" 1>&6
-echo "configure:2733: checking for vfork" >&5
+echo "configure:2735: checking for vfork" >&5
if eval "test \"`echo '$''{'ac_cv_func_vfork'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 2738 "configure"
+#line 2740 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char vfork(); below. */
@@ -2757,7 +2759,7 @@ vfork();
; return 0; }
EOF
-if { (eval echo configure:2761: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2763: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_vfork=yes"
else
@@ -2779,7 +2781,7 @@ fi
ac_cv_func_vfork_works=$ac_cv_func_vfork
else
cat > conftest.$ac_ext <<EOF
-#line 2783 "configure"
+#line 2785 "configure"
#include "confdefs.h"
/* Thanks to Paul Eggert for this test. */
#include <stdio.h>
@@ -2874,7 +2876,7 @@ main() {
}
}
EOF
-if { (eval echo configure:2878: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2880: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_func_vfork_works=yes
else
@@ -2906,12 +2908,12 @@ fi
for ac_func in _doprnt
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2910: checking for $ac_func" >&5
+echo "configure:2912: 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 2915 "configure"
+#line 2917 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -2934,7 +2936,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:2938: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2940: \"$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
@@ -2964,12 +2966,12 @@ done
for ac_func in _doprnt
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2968: checking for $ac_func" >&5
+echo "configure:2970: 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 2973 "configure"
+#line 2975 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -2992,7 +2994,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:2996: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2998: \"$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
@@ -3020,19 +3022,19 @@ done
for v in $vars; do
echo $ac_n "checking for $v""... $ac_c" 1>&6
-echo "configure:3024: checking for $v" >&5
+echo "configure:3026: 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 3029 "configure"
+#line 3031 "configure"
#include "confdefs.h"
int *p;
int main() {
extern int $v []; p = $v;
; return 0; }
EOF
-if { (eval echo configure:3036: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3038: \"$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
@@ -3058,12 +3060,12 @@ EOF
for ac_func in $checkfuncs
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:3062: checking for $ac_func" >&5
+echo "configure:3064: 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 3067 "configure"
+#line 3069 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -3086,7 +3088,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:3090: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3092: \"$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
@@ -3111,12 +3113,12 @@ fi
done
echo $ac_n "checking whether canonicalize_file_name must be declared""... $ac_c" 1>&6
-echo "configure:3115: checking whether canonicalize_file_name must be declared" >&5
+echo "configure:3117: checking whether canonicalize_file_name must be declared" >&5
if eval "test \"`echo '$''{'libiberty_cv_decl_needed_canonicalize_file_name'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3120 "configure"
+#line 3122 "configure"
#include "confdefs.h"
#include "confdefs.h"
@@ -3138,7 +3140,7 @@ int main() {
char *(*pfn) = (char *(*)) canonicalize_file_name
; return 0; }
EOF
-if { (eval echo configure:3142: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3144: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
libiberty_cv_decl_needed_canonicalize_file_name=no
else
@@ -3174,17 +3176,17 @@ 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:3178: checking for $ac_hdr" >&5
+echo "configure:3180: 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 3183 "configure"
+#line 3185 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:3188: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:3190: \"$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*
@@ -3213,12 +3215,12 @@ done
for ac_func in getpagesize
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:3217: checking for $ac_func" >&5
+echo "configure:3219: 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 3222 "configure"
+#line 3224 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -3241,7 +3243,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:3245: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3247: \"$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
@@ -3266,7 +3268,7 @@ fi
done
echo $ac_n "checking for working mmap""... $ac_c" 1>&6
-echo "configure:3270: checking for working mmap" >&5
+echo "configure:3272: 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
@@ -3274,7 +3276,7 @@ else
ac_cv_func_mmap_fixed_mapped=no
else
cat > conftest.$ac_ext <<EOF
-#line 3278 "configure"
+#line 3280 "configure"
#include "confdefs.h"
/* Thanks to Mike Haertel and Jim Avera for this test.
@@ -3414,7 +3416,7 @@ main()
}
EOF
-if { (eval echo configure:3418: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3420: \"$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
@@ -3438,7 +3440,7 @@ fi
echo $ac_n "checking for working strncmp""... $ac_c" 1>&6
-echo "configure:3442: checking for working strncmp" >&5
+echo "configure:3444: 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
@@ -3446,7 +3448,7 @@ else
ac_cv_func_strncmp_works=no
else
cat > conftest.$ac_ext <<EOF
-#line 3450 "configure"
+#line 3452 "configure"
#include "confdefs.h"
/* Test by Jim Wilson and Kaveh Ghazi.
@@ -3510,7 +3512,7 @@ main ()
}
EOF
-if { (eval echo configure:3514: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3516: \"$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
diff --git a/libiberty/configure.in b/libiberty/configure.in
index d6c2649feb4..e142cf501c8 100644
--- a/libiberty/configure.in
+++ b/libiberty/configure.in
@@ -185,6 +185,7 @@ funcs="$funcs random"
funcs="$funcs rename"
funcs="$funcs rindex"
funcs="$funcs setenv"
+funcs="$funcs snprintf"
funcs="$funcs sigsetmask"
funcs="$funcs stpcpy"
funcs="$funcs stpncpy"
@@ -201,6 +202,7 @@ funcs="$funcs tmpnam"
funcs="$funcs vasprintf"
funcs="$funcs vfprintf"
funcs="$funcs vprintf"
+funcs="$funcs vsnprintf"
funcs="$funcs vsprintf"
funcs="$funcs waitpid"
@@ -221,7 +223,7 @@ if test "x" = "y"; then
AC_CHECK_FUNCS(strcasecmp setenv stpcpy stpncpy strchr strdup strncasecmp strrchr strstr)
AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf)
AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal)
- AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs)
+ AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs snprintf vsnprintf)
AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl)
AC_CHECK_FUNCS(realpath canonicalize_file_name)
AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
diff --git a/libiberty/functions.texi b/libiberty/functions.texi
index bb35549df19..4261d864676 100644
--- a/libiberty/functions.texi
+++ b/libiberty/functions.texi
@@ -673,6 +673,19 @@ be the value @code{1}).
@end deftypefn
+@c snprintf.c:28
+@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, ...)
+
+This function is similar to sprintf, but it will print at most @var{n}
+characters. On error the return value is -1, otherwise it returns the
+number of characters that would have been printed had @var{n} been
+sufficiently large, regardless of the actual value of @var{n}. Note
+some pre-C99 system libraries do not implement this correctly so users
+cannot generally rely on the return value if the system version of
+this function is used.
+
+@end deftypefn
+
@c spaces.c:22
@deftypefn Extension char* spaces (int @var{count})
@@ -929,6 +942,19 @@ nonstandard but common function @code{_doprnt}.
@end deftypefn
+@c vsnprintf.c:28
+@deftypefn Supplemental int vsnprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, va_list @var{ap})
+
+This function is similar to vsprintf, but it will print at most
+@var{n} characters. On error the return value is -1, otherwise it
+returns the number of characters that would have been printed had
+@var{n} been sufficiently large, regardless of the actual value of
+@var{n}. Note some pre-C99 system libraries do not implement this
+correctly so users cannot generally rely on the return value if the
+system version of this function is used.
+
+@end deftypefn
+
@c waitpid.c:3
@deftypefn Supplemental int waitpid (int @var{pid}, int *@var{status}, int)
diff --git a/libiberty/snprintf.c b/libiberty/snprintf.c
new file mode 100644
index 00000000000..89164695b50
--- /dev/null
+++ b/libiberty/snprintf.c
@@ -0,0 +1,65 @@
+/* Implement the snprintf function.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
+
+This file is part of the libiberty library. This library 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 library 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 GNU CC; see the file COPYING. If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+As a special exception, if you link this library with files
+compiled with a GNU compiler to produce an executable, this does not cause
+the resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why
+the executable file might be covered by the GNU General Public License. */
+
+/*
+
+@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, ...)
+
+This function is similar to sprintf, but it will print at most @var{n}
+characters. On error the return value is -1, otherwise it returns the
+number of characters that would have been printed had @var{n} been
+sufficiently large, regardless of the actual value of @var{n}. Note
+some pre-C99 system libraries do not implement this correctly so users
+cannot generally rely on the return value if the system version of
+this function is used.
+
+@end deftypefn
+
+*/
+
+#include "ansidecl.h"
+
+#ifdef ANSI_PROTOTYPES
+#include <stdarg.h>
+#include <stddef.h>
+#else
+#include <varargs.h>
+#define size_t unsigned long
+#endif
+
+int vsnprintf PARAMS ((char *, size_t, const char *, va_list));
+
+int
+snprintf VPARAMS ((char *s, size_t n, const char *format, ...))
+{
+ int result;
+ VA_OPEN (ap, format);
+ VA_FIXEDARG (ap, char *, s);
+ VA_FIXEDARG (ap, size_t, n);
+ VA_FIXEDARG (ap, const char *, format);
+ result = vsnprintf (s, n, format, ap);
+ VA_CLOSE (ap);
+ return result;
+}
diff --git a/libiberty/vsnprintf.c b/libiberty/vsnprintf.c
new file mode 100644
index 00000000000..9328e430097
--- /dev/null
+++ b/libiberty/vsnprintf.c
@@ -0,0 +1,149 @@
+/* Implement the vsnprintf function.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
+
+This file is part of the libiberty library. This library 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 library 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 GNU CC; see the file COPYING. If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+As a special exception, if you link this library with files
+compiled with a GNU compiler to produce an executable, this does not cause
+the resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why
+the executable file might be covered by the GNU General Public License. */
+
+/*
+
+@deftypefn Supplemental int vsnprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, va_list @var{ap})
+
+This function is similar to vsprintf, but it will print at most
+@var{n} characters. On error the return value is -1, otherwise it
+returns the number of characters that would have been printed had
+@var{n} been sufficiently large, regardless of the actual value of
+@var{n}. Note some pre-C99 system libraries do not implement this
+correctly so users cannot generally rely on the return value if the
+system version of this function is used.
+
+@end deftypefn
+
+*/
+
+#include "config.h"
+#include "ansidecl.h"
+
+#ifdef ANSI_PROTOTYPES
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include "libiberty.h"
+
+/* This implementation relies on a working vasprintf. */
+int
+vsnprintf (s, n, format, ap)
+ char * s;
+ size_t n;
+ const char *format;
+ va_list ap;
+{
+ char *buf = 0;
+ int result = vasprintf (&buf, format, ap);
+
+ if (!buf)
+ return -1;
+ if (result < 0)
+ {
+ free (buf);
+ return -1;
+ }
+
+ result = strlen (buf);
+ if (n > 0)
+ {
+ strncpy (s, buf, n);
+ if (n - 1 < (size_t) result)
+ s[n - 1] = 0;
+ }
+ free (buf);
+ return result;
+}
+
+#ifdef TEST
+/* Set the buffer to a known state. */
+#define CLEAR(BUF) do { memset ((BUF), 'X', sizeof (BUF)); (BUF)[14] = '\0'; } while (0)
+/* For assertions. */
+#define VERIFY(P) do { if (!(P)) abort(); } while (0)
+
+static int ATTRIBUTE_PRINTF_3
+checkit VPARAMS ((char *s, size_t n, const char *format, ...))
+{
+ int result;
+ VA_OPEN (ap, format);
+ VA_FIXEDARG (ap, char *, s);
+ VA_FIXEDARG (ap, size_t, n);
+ VA_FIXEDARG (ap, const char *, format);
+ result = vsnprintf (s, n, format, ap);
+ VA_CLOSE (ap);
+ return result;
+}
+
+extern int main PARAMS ((void));
+int
+main ()
+{
+ char buf[128];
+ int status;
+
+ CLEAR (buf);
+ status = checkit (buf, 10, "%s:%d", "foobar", 9);
+ VERIFY (status==8 && strcmp (buf, "foobar:9") == 0);
+
+ CLEAR (buf);
+ status = checkit (buf, 9, "%s:%d", "foobar", 9);
+ VERIFY (status==8 && strcmp (buf, "foobar:9") == 0);
+
+ CLEAR (buf);
+ status = checkit (buf, 8, "%s:%d", "foobar", 9);
+ VERIFY (status==8 && strcmp (buf, "foobar:") == 0);
+
+ CLEAR (buf);
+ status = checkit (buf, 7, "%s:%d", "foobar", 9);
+ VERIFY (status==8 && strcmp (buf, "foobar") == 0);
+
+ CLEAR (buf);
+ status = checkit (buf, 6, "%s:%d", "foobar", 9);
+ VERIFY (status==8 && strcmp (buf, "fooba") == 0);
+
+ CLEAR (buf);
+ status = checkit (buf, 2, "%s:%d", "foobar", 9);
+ VERIFY (status==8 && strcmp (buf, "f") == 0);
+
+ CLEAR (buf);
+ status = checkit (buf, 1, "%s:%d", "foobar", 9);
+ VERIFY (status==8 && strcmp (buf, "") == 0);
+
+ CLEAR (buf);
+ status = checkit (buf, 0, "%s:%d", "foobar", 9);
+ VERIFY (status==8 && strcmp (buf, "XXXXXXXXXXXXXX") == 0);
+
+ return 0;
+}
+#endif /* TEST */