echo "$ac_t""$ac_cv_type_size_t" 1>&6
if test $ac_cv_type_size_t = no; then
cat >> confdefs.h <<\EOF
-#define size_t int
+#define size_t unsigned int
+EOF
+
+fi
+
+echo $ac_n "checking for ssize_t""... $ac_c" 1>&6
+echo "configure:2177: checking for ssize_t" >&5
+if eval "test \"`echo '$''{'ac_cv_type_ssize_t'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 2182 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+#if STDC_HEADERS
+#include <stdlib.h>
+#include <stddef.h>
+#endif
+EOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ egrep "ssize_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
+ rm -rf conftest*
+ ac_cv_type_ssize_t=yes
+else
+ rm -rf conftest*
+ ac_cv_type_ssize_t=no
+fi
+rm -f conftest*
+
+fi
+echo "$ac_t""$ac_cv_type_ssize_t" 1>&6
+if test $ac_cv_type_ssize_t = no; then
+ cat >> confdefs.h <<\EOF
+#define ssize_t int
EOF
fi
echo $ac_n "checking for off_t""... $ac_c" 1>&6
-echo "configure:2177: checking for off_t" >&5
+echo "configure:2210: checking for off_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_off_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 2182 "configure"
+#line 2215 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
fi
echo $ac_n "checking for mode_t""... $ac_c" 1>&6
-echo "configure:2210: checking for mode_t" >&5
+echo "configure:2243: checking for mode_t" >&5
if eval "test \"`echo '$''{'ac_cv_type_mode_t'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 2215 "configure"
+#line 2248 "configure"
#include "confdefs.h"
#include <sys/types.h>
#if STDC_HEADERS
echo $ac_n "checking for main in -lnsl""... $ac_c" 1>&6
-echo "configure:2244: checking for main in -lnsl" >&5
+echo "configure:2277: checking for main in -lnsl" >&5
ac_lib_var=`echo nsl'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lnsl $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2252 "configure"
+#line 2285 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:2259: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2292: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
fi
echo $ac_n "checking for main in -lsocket""... $ac_c" 1>&6
-echo "configure:2287: checking for main in -lsocket" >&5
+echo "configure:2320: checking for main in -lsocket" >&5
ac_lib_var=`echo socket'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lsocket $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2295 "configure"
+#line 2328 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:2302: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2335: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
fi
echo $ac_n "checking for main in -lgnumalloc""... $ac_c" 1>&6
-echo "configure:2330: checking for main in -lgnumalloc" >&5
+echo "configure:2363: checking for main in -lgnumalloc" >&5
ac_lib_var=`echo gnumalloc'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lgnumalloc $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2338 "configure"
+#line 2371 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:2345: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2378: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
;;
*)
echo $ac_n "checking for main in -lmalloc""... $ac_c" 1>&6
-echo "configure:2382: checking for main in -lmalloc" >&5
+echo "configure:2415: checking for main in -lmalloc" >&5
ac_lib_var=`echo malloc'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lmalloc $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2390 "configure"
+#line 2423 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:2397: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2430: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
esac
fi
echo $ac_n "checking for main in -lbsd""... $ac_c" 1>&6
-echo "configure:2428: checking for main in -lbsd" >&5
+echo "configure:2461: checking for main in -lbsd" >&5
ac_lib_var=`echo bsd'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lbsd $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2436 "configure"
+#line 2469 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:2443: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2476: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
fi
echo $ac_n "checking for main in -lregex""... $ac_c" 1>&6
-echo "configure:2471: checking for main in -lregex" >&5
+echo "configure:2504: checking for main in -lregex" >&5
ac_lib_var=`echo regex'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lregex $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2479 "configure"
+#line 2512 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:2486: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2519: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
fi
echo $ac_n "checking for inet_aton in -lresolv""... $ac_c" 1>&6
-echo "configure:2507: checking for inet_aton in -lresolv" >&5
+echo "configure:2540: checking for inet_aton in -lresolv" >&5
ac_lib_var=`echo resolv'_'inet_aton | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lresolv $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2515 "configure"
+#line 2548 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
inet_aton()
; return 0; }
EOF
-if { (eval echo configure:2526: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2559: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
echo "$ac_t""yes" 1>&6
echo $ac_n "checking for inet_aton in -l44bsd""... $ac_c" 1>&6
-echo "configure:2542: checking for inet_aton in -l44bsd" >&5
+echo "configure:2575: checking for inet_aton in -l44bsd" >&5
ac_lib_var=`echo 44bsd'_'inet_aton | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-l44bsd $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2550 "configure"
+#line 2583 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
inet_aton()
; return 0; }
EOF
-if { (eval echo configure:2561: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2594: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
fi
echo $ac_n "checking for main in -lresolv""... $ac_c" 1>&6
-echo "configure:2593: checking for main in -lresolv" >&5
+echo "configure:2626: checking for main in -lresolv" >&5
ac_lib_var=`echo resolv'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lresolv $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2601 "configure"
+#line 2634 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:2608: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2641: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
fi
echo $ac_n "checking for main in -lm""... $ac_c" 1>&6
-echo "configure:2636: checking for main in -lm" >&5
+echo "configure:2669: checking for main in -lm" >&5
ac_lib_var=`echo m'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lm $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2644 "configure"
+#line 2677 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:2651: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2684: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
echo $ac_n "checking for crypt in -lcrypt""... $ac_c" 1>&6
-echo "configure:2680: checking for crypt in -lcrypt" >&5
+echo "configure:2713: checking for crypt in -lcrypt" >&5
ac_lib_var=`echo crypt'_'crypt | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lcrypt $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 2688 "configure"
+#line 2721 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
crypt()
; return 0; }
EOF
-if { (eval echo configure:2699: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2732: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2800: checking for $ac_func" >&5
+echo "configure:2833: 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 2805 "configure"
+#line 2838 "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:2828: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2861: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
echo $ac_n "checking if GNUregex needs to be compiled""... $ac_c" 1>&6
-echo "configure:2854: checking if GNUregex needs to be compiled" >&5
+echo "configure:2887: checking if GNUregex needs to be compiled" >&5
if test "$ac_cv_func_regcomp" = "no" ; then
USE_GNUREGEX="yes"
else
for ac_func in \
tempnam \
strerror \
+ snprintf \
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2886: checking for $ac_func" >&5
+echo "configure:2920: 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 2891 "configure"
+#line 2925 "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:2914: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2948: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
echo $ac_n "checking Default FD_SETSIZE value""... $ac_c" 1>&6
-echo "configure:2942: checking Default FD_SETSIZE value" >&5
+echo "configure:2976: checking Default FD_SETSIZE value" >&5
if test "$cross_compiling" = yes; then
DEFAULT_FD_SETSIZE=256
else
cat > conftest.$ac_ext <<EOF
-#line 2947 "configure"
+#line 2981 "configure"
#include "confdefs.h"
#if HAVE_STDIO_H
}
EOF
-if { (eval echo configure:2971: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3005: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
then
DEFAULT_FD_SETSIZE=`cat conftestval`
else
echo $ac_n "checking Maximum number of filedescriptors we can open""... $ac_c" 1>&6
-echo "configure:2990: checking Maximum number of filedescriptors we can open" >&5
+echo "configure:3024: checking Maximum number of filedescriptors we can open" >&5
if test "$cross_compiling" = yes; then
SQUID_MAXFD=256
else
cat > conftest.$ac_ext <<EOF
-#line 2995 "configure"
+#line 3029 "configure"
#include "confdefs.h"
#include <stdio.h>
}
EOF
-if { (eval echo configure:3047: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3081: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
then
SQUID_MAXFD=`cat conftestval`
else
echo $ac_n "checking Default UDP send buffer size""... $ac_c" 1>&6
-echo "configure:3066: checking Default UDP send buffer size" >&5
+echo "configure:3100: checking Default UDP send buffer size" >&5
if test "$cross_compiling" = yes; then
SQUID_UDP_SO_SNDBUF=16384
else
cat > conftest.$ac_ext <<EOF
-#line 3071 "configure"
+#line 3105 "configure"
#include "confdefs.h"
#include <stdlib.h>
}
EOF
-if { (eval echo configure:3090: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3124: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
then
SQUID_UDP_SO_SNDBUF=`cat conftestval`
else
echo $ac_n "checking Default UDP receive buffer size""... $ac_c" 1>&6
-echo "configure:3109: checking Default UDP receive buffer size" >&5
+echo "configure:3143: checking Default UDP receive buffer size" >&5
if test "$cross_compiling" = yes; then
SQUID_UDP_SO_RCVBUF=16384
else
cat > conftest.$ac_ext <<EOF
-#line 3114 "configure"
+#line 3148 "configure"
#include "confdefs.h"
#include <stdlib.h>
}
EOF
-if { (eval echo configure:3133: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3167: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
then
SQUID_UDP_SO_RCVBUF=`cat conftestval`
else
echo $ac_n "checking Default TCP send buffer size""... $ac_c" 1>&6
-echo "configure:3152: checking Default TCP send buffer size" >&5
+echo "configure:3186: checking Default TCP send buffer size" >&5
if test "$cross_compiling" = yes; then
SQUID_TCP_SO_SNDBUF=16384
else
cat > conftest.$ac_ext <<EOF
-#line 3157 "configure"
+#line 3191 "configure"
#include "confdefs.h"
#include <stdlib.h>
}
EOF
-if { (eval echo configure:3176: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3210: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
then
SQUID_TCP_SO_SNDBUF=`cat conftestval`
else
echo $ac_n "checking Default TCP receive buffer size""... $ac_c" 1>&6
-echo "configure:3195: checking Default TCP receive buffer size" >&5
+echo "configure:3229: checking Default TCP receive buffer size" >&5
if test "$cross_compiling" = yes; then
SQUID_TCP_SO_RCVBUF=16384
else
cat > conftest.$ac_ext <<EOF
-#line 3200 "configure"
+#line 3234 "configure"
#include "confdefs.h"
#include <stdlib.h>
}
EOF
-if { (eval echo configure:3219: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3253: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
then
SQUID_TCP_SO_RCVBUF=`cat conftestval`
else
echo $ac_n "checking if sys_errlist is already defined""... $ac_c" 1>&6
-echo "configure:3238: checking if sys_errlist is already defined" >&5
+echo "configure:3272: checking if sys_errlist is already defined" >&5
cat > conftest.$ac_ext <<EOF
-#line 3240 "configure"
+#line 3274 "configure"
#include "confdefs.h"
#include <stdio.h>
int main() {
char *s = sys_errlist[0];
; return 0; }
EOF
-if { (eval echo configure:3247: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3281: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
echo "$ac_t""yes" 1>&6
else
rm -f conftest*
echo $ac_n "checking for libresolv _dns_ttl_ hack""... $ac_c" 1>&6
-echo "configure:3263: checking for libresolv _dns_ttl_ hack" >&5
+echo "configure:3297: checking for libresolv _dns_ttl_ hack" >&5
cat > conftest.$ac_ext <<EOF
-#line 3265 "configure"
+#line 3299 "configure"
#include "confdefs.h"
extern int _dns_ttl_;
int main() {
return _dns_ttl_;
; return 0; }
EOF
-if { (eval echo configure:3272: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:3306: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
rm -rf conftest*
echo "$ac_t""yes" 1>&6
cat >> confdefs.h <<\EOF
--- /dev/null
+/**************************************************************
+ * Original:
+ * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
+ * A bombproof version of doprnt (dopr) included.
+ * Sigh. This sort of thing is always nasty do deal with. Note that
+ * the version here does not include floating point...
+ *
+ * snprintf() is used instead of sprintf() as it does limit checks
+ * for string length. This covers a nasty loophole.
+ *
+ * The other functions are there to prevent NULL pointers from
+ * causing nast effects.
+ **************************************************************/
+
+/* Original RCS tag:
+ Id: snprintf.c,v 1.1 1995/08/19 20:36:09 papowell Exp */
+
+static void dopr();
+static char *end;
+
+#include "config.h"
+
+#if HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#if HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if HAVE_CTYPE_H
+#include <ctype.h>
+#endif
+
+/* varargs declarations: */
+
+#if defined(HAVE_STDARG_H)
+#include <stdarg.h>
+#define HAVE_STDARGS /* let's hope that works everywhere (mj) */
+#define VA_LOCAL_DECL va_list ap;
+#define VA_START(f) va_start(ap, f)
+#define VA_SHIFT(v,t) ; /* no-op for ANSI */
+#define VA_END va_end(ap)
+#else
+#if defined(HAVE_VARARGS_H)
+#include <varargs.h>
+#undef HAVE_STDARGS
+#define VA_LOCAL_DECL va_list ap;
+#define VA_START(f) va_start(ap) /* f is ignored! */
+#define VA_SHIFT(v,t) v = va_arg(ap,t)
+#define VA_END va_end(ap)
+#else
+XX **NO VARARGS ** XX
+#endif
+#endif
+
+#ifdef HAVE_STDARGS
+int snprintf(char *str, size_t count, const char *fmt,...);
+int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
+#else
+int snprintf();
+int vsnprintf();
+#endif
+
+int
+vsnprintf(str, count, fmt, args)
+ char *str;
+ size_t count;
+ const char *fmt;
+ va_list args;
+{
+ str[0] = 0;
+ end = str + count - 1;
+ dopr(str, fmt, args);
+ if (count > 0) {
+ end[0] = 0;
+ }
+ return (strlen(str));
+}
+
+/* VARARGS3 */
+#ifdef HAVE_STDARGS
+int
+snprintf(char *str, size_t count, const char *fmt,...)
+#else
+int
+snprintf(va_alist)
+ va_dcl
+#endif
+{
+#ifndef HAVE_STDARGS
+ char *str;
+ size_t count;
+ char *fmt;
+#endif
+ VA_LOCAL_DECL
+
+ VA_START(fmt);
+ VA_SHIFT(str, char *);
+ VA_SHIFT(count, size_t);
+ VA_SHIFT(fmt, char *);
+ (void) vsnprintf(str, count, fmt, ap);
+ VA_END;
+ return (strlen(str));
+}
+
+/*
+ * dopr(): poor man's version of doprintf
+ */
+
+static void fmtstr(char *value, int ljust, int len, int zpad);
+static void fmtnum(long value, int base, int dosign,
+ int ljust, int len, int zpad);
+static void dostr(char *);
+static char *output;
+static void dopr_outch(int c);
+
+static void
+dopr(buffer, format, args)
+ char *buffer;
+ char *format;
+ va_list args;
+{
+ int ch;
+ long value;
+ int longflag = 0;
+ char *strvalue;
+ int ljust;
+ int len;
+ int zpad;
+
+ output = buffer;
+ while ((ch = *format++)) {
+ switch (ch) {
+ case '%':
+ ljust = len = zpad = 0;
+ nextch:
+ ch = *format++;
+ switch (ch) {
+ case 0:
+ dostr("**end of format**");
+ return;
+ case '-':
+ ljust = 1;
+ goto nextch;
+ case '0': /* set zero padding if len not set */
+ if (len == 0)
+ zpad = '0';
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ len = len * 10 + ch - '0';
+ goto nextch;
+ case 'l':
+ longflag = 1;
+ goto nextch;
+ case 'u':
+ case 'U':
+ /*fmtnum(value,base,dosign,ljust,len,zpad) */
+ if (longflag) {
+ value = va_arg(args, long);
+ } else {
+ value = va_arg(args, int);
+ }
+ fmtnum(value, 10, 0, ljust, len, zpad);
+ break;
+ case 'o':
+ case 'O':
+ /*fmtnum(value,base,dosign,ljust,len,zpad) */
+ if (longflag) {
+ value = va_arg(args, long);
+ } else {
+ value = va_arg(args, int);
+ }
+ fmtnum(value, 8, 0, ljust, len, zpad);
+ break;
+ case 'd':
+ case 'D':
+ if (longflag) {
+ value = va_arg(args, long);
+ } else {
+ value = va_arg(args, int);
+ }
+ fmtnum(value, 10, 1, ljust, len, zpad);
+ break;
+ case 'x':
+ if (longflag) {
+ value = va_arg(args, long);
+ } else {
+ value = va_arg(args, int);
+ }
+ fmtnum(value, 16, 0, ljust, len, zpad);
+ break;
+ case 'X':
+ if (longflag) {
+ value = va_arg(args, long);
+ } else {
+ value = va_arg(args, int);
+ }
+ fmtnum(value, -16, 0, ljust, len, zpad);
+ break;
+ case 's':
+ strvalue = va_arg(args, char *);
+ fmtstr(strvalue, ljust, len, zpad);
+ break;
+ case 'c':
+ ch = va_arg(args, int);
+ dopr_outch(ch);
+ break;
+ case '%':
+ dopr_outch(ch);
+ continue;
+ default:
+ dostr("???????");
+ }
+ longflag = 0;
+ break;
+ default:
+ dopr_outch(ch);
+ break;
+ }
+ }
+ *output = 0;
+}
+
+static void
+fmtstr(value, ljust, len, zpad)
+ char *value;
+ int ljust, len, zpad;
+{
+ int padlen, strlen; /* amount to pad */
+
+ if (value == 0) {
+ value = "<NULL>";
+ }
+ for (strlen = 0; value[strlen]; ++strlen); /* strlen */
+ padlen = len - strlen;
+ if (padlen < 0)
+ padlen = 0;
+ if (ljust)
+ padlen = -padlen;
+ while (padlen > 0) {
+ dopr_outch(' ');
+ --padlen;
+ }
+ dostr(value);
+ while (padlen < 0) {
+ dopr_outch(' ');
+ ++padlen;
+ }
+}
+
+static void
+fmtnum(value, base, dosign, ljust, len, zpad)
+ long value;
+ int base, dosign, ljust, len, zpad;
+{
+ int signvalue = 0;
+ unsigned long uvalue;
+ char convert[20];
+ int place = 0;
+ int padlen = 0; /* amount to pad */
+ int caps = 0;
+
+ /* DEBUGP(("value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
+ * value, base, dosign, ljust, len, zpad )); */
+ uvalue = value;
+ if (dosign) {
+ if (value < 0) {
+ signvalue = '-';
+ uvalue = -value;
+ }
+ }
+ if (base < 0) {
+ caps = 1;
+ base = -base;
+ }
+ do {
+ convert[place++] =
+ (caps ? "0123456789ABCDEF" : "0123456789abcdef")
+ [uvalue % (unsigned) base];
+ uvalue = (uvalue / (unsigned) base);
+ } while (uvalue);
+ convert[place] = 0;
+ padlen = len - place;
+ if (padlen < 0)
+ padlen = 0;
+ if (ljust)
+ padlen = -padlen;
+ /* DEBUGP(( "str '%s', place %d, sign %c, padlen %d\n",
+ * convert,place,signvalue,padlen)); */
+ if (zpad && padlen > 0) {
+ if (signvalue) {
+ dopr_outch(signvalue);
+ --padlen;
+ signvalue = 0;
+ }
+ while (padlen > 0) {
+ dopr_outch(zpad);
+ --padlen;
+ }
+ }
+ while (padlen > 0) {
+ dopr_outch(' ');
+ --padlen;
+ }
+ if (signvalue)
+ dopr_outch(signvalue);
+ while (place > 0)
+ dopr_outch(convert[--place]);
+ while (padlen < 0) {
+ dopr_outch(' ');
+ ++padlen;
+ }
+}
+
+static void
+dostr(str)
+ char *str;
+{
+ while (*str)
+ dopr_outch(*str++);
+}
+
+static void
+dopr_outch(c)
+ int c;
+{
+ if (iscntrl(c) && c != '\n' && c != '\t') {
+ c = '@' + (c & 0x1F);
+ if (end == 0 || output < end) {
+ *output++ = '^';
+ }
+ }
+ if (end == 0 || output < end) {
+ *output++ = c;
+ }
+}