]> sjero.net Git - wget/blobdiff - src/snprintf.c
[svn] Applied Dennis Smit's --preserve-permissions patch.
[wget] / src / snprintf.c
index 3202c5c08d8763064450fe4b95abb91c4c5a2465..5baa98b6bb59ef9087bbe66aa75c13e5b947be90 100644 (file)
  *    fixed return value to comply with C99
  *    fixed handling of snprintf(NULL, ...)
  *
- *  Hrvoje Niksic <hniksic@arsdigita.com> 2000-11-04
+ *  Hrvoje Niksic <hniksic@xemacs.org> 2000-11-04
  *    include <config.h> instead of "config.h".
  *    moved TEST_SNPRINTF stuff out of HAVE_SNPRINTF ifdef.
  *    include <stdio.h> for NULL.
  *    added support and test cases for long long.
  *    don't declare argument types to (v)snprintf if stdarg is not used.
+ *    use int instead of short int as 2nd arg to va_arg.
  *
  **************************************************************/
 
@@ -78,9 +79,9 @@
 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
 
 #include <string.h>
-#include <ctype.h>
 #include <sys/types.h>
 #include <stdio.h>             /* for NULL */
+#include <safe-ctype.h>
 
 /* varargs declarations: */
 
 #define LDOUBLE double
 #endif
 
-#ifdef HAVE_LONG_LONG
+#if SIZEOF_LONG_LONG != 0
 # define LLONG long long
 #else
 # define LLONG long
@@ -227,7 +228,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
       }
       break;
     case DP_S_MIN:
-      if (isdigit(ch)) 
+      if ('0' <= ch && ch <= '9')
       {
        min = 10*min + char_to_int (ch);
        ch = *format++;
@@ -251,7 +252,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
        state = DP_S_MOD;
       break;
     case DP_S_MAX:
-      if (isdigit(ch)) 
+      if ('0' <= ch && ch <= '9')
       {
        if (max < 0)
          max = 0;
@@ -308,7 +309,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
       case 'd':
       case 'i':
        if (cflags == DP_C_SHORT) 
-         value = va_arg (args, short int);
+         value = (short int)va_arg (args, int);
        else if (cflags == DP_C_LONG)
          value = va_arg (args, long int);
        else if (cflags == DP_C_LLONG)
@@ -320,7 +321,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
       case 'o':
        flags |= DP_F_UNSIGNED;
        if (cflags == DP_C_SHORT)
-         value = va_arg (args, unsigned short int);
+         value = (unsigned short int)va_arg (args, unsigned int);
        else if (cflags == DP_C_LONG)
          value = va_arg (args, unsigned long int);
        else if (cflags == DP_C_LLONG)
@@ -332,7 +333,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
       case 'u':
        flags |= DP_F_UNSIGNED;
        if (cflags == DP_C_SHORT)
-         value = va_arg (args, unsigned short int);
+         value = (unsigned short int)va_arg (args, unsigned int);
        else if (cflags == DP_C_LONG)
          value = va_arg (args, unsigned long int);
        else if (cflags == DP_C_LLONG)
@@ -346,7 +347,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
       case 'x':
        flags |= DP_F_UNSIGNED;
        if (cflags == DP_C_SHORT)
-         value = va_arg (args, unsigned short int);
+         value = (unsigned short int)va_arg (args, unsigned int);
        else if (cflags == DP_C_LONG)
          value = va_arg (args, unsigned long int);
        else if (cflags == DP_C_LLONG)
@@ -848,7 +849,7 @@ int main (void)
     NULL
   };
   long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
-#ifdef HAVE_LONG_LONG
+#if SIZEOF_LONG_LONG != 0
   char *llong_fmt[] = {
     "%lld",            "%llu",
     "%-1.5lld",                "%-1.5llu",
@@ -904,7 +905,7 @@ int main (void)
       num++;
     }
 
-#ifdef HAVE_LONG_LONG
+#if SIZEOF_LONG_LONG != 0
   for (x = 0; llong_fmt[x] != NULL ; x++)
     for (y = 0; llong_nums[y] != 0 ; y++)
     {