[PATCH] snprintf %lld and %qd support.

Ben Lindstrom mouring at pconline.com
Fri Sep 29 14:56:09 EST 2000


Added support for most Long Long options.  Even if I suspect most of them
will never be used (if they are even vaid.. I've never seen %llx, %llo,
%qx, and %qo before in my life).

Does not resolve the NeXT sftp-server issue, but should help those that
had to suffered when we switched snprintf() to get NeXT support
integrated into the portable tree. =)

- Ben

-------------- next part --------------
--- ../onext/bsd-snprintf.c	Tue Aug 29 17:21:22 2000
+++ bsd-snprintf.c	Thu Sep 28 18:30:05 2000
@@ -38,6 +38,10 @@
  *    missing.  Some systems only have snprintf() but not vsnprintf(), so
  *    the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
  *
+ *  Ben Lindstrom <mouring at pconline.com> 09/27/00 for OpenSSH
+ *    Welcome to the world of %lld and %qd support.  With other
+ *    long long support.  This is needed for sftp-server to work
+ *    right.
  **************************************************************/
 
 #include "config.h"
@@ -111,9 +115,10 @@
 #define DP_F_UNSIGNED 	(1 << 6)
 
 /* Conversion Flags */
-#define DP_C_SHORT   1
-#define DP_C_LONG    2
-#define DP_C_LDOUBLE 3
+#define DP_C_SHORT     1
+#define DP_C_LONG      2
+#define DP_C_LDOUBLE   3
+#define DP_C_LONG_LONG 4
 
 #define char_to_int(p) (p - '0')
 #ifndef MAX
@@ -222,7 +227,6 @@
 	state = DP_S_MOD;
       break;
     case DP_S_MOD:
-      /* Currently, we don't support Long Long, bummer */
       switch (ch) 
       {
       case 'h':
@@ -232,7 +236,15 @@
       case 'l':
 	cflags = DP_C_LONG;
 	ch = *format++;
+        if (ch == 'l') {
+           cflags = DP_C_LONG_LONG;
+           ch = *format++;
+        }
 	break;
+      case 'q':
+	cflags = DP_C_LONG_LONG;
+        ch = *format++;
+        break;
       case 'L':
 	cflags = DP_C_LDOUBLE;
 	ch = *format++;
@@ -251,6 +263,8 @@
 	  value = va_arg (args, short int);
 	else if (cflags == DP_C_LONG)
 	  value = va_arg (args, long int);
+	else if (cflags == DP_C_LONG_LONG)
+	  value = va_arg (args, long long);
 	else
 	  value = va_arg (args, int);
 	fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
@@ -261,6 +275,8 @@
 	  value = va_arg (args, unsigned short int);
 	else if (cflags == DP_C_LONG)
 	  value = va_arg (args, unsigned long int);
+	else if (cflags == DP_C_LONG_LONG)
+	  value = va_arg (args, unsigned long long);
 	else
 	  value = va_arg (args, unsigned int);
 	fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
@@ -271,6 +287,8 @@
 	  value = va_arg (args, unsigned short int);
 	else if (cflags == DP_C_LONG)
 	  value = va_arg (args, unsigned long int);
+	else if (cflags == DP_C_LONG_LONG)
+	  value = va_arg (args, unsigned long long);
 	else
 	  value = va_arg (args, unsigned int);
 	fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
@@ -283,6 +301,8 @@
 	  value = va_arg (args, unsigned short int);
 	else if (cflags == DP_C_LONG)
 	  value = va_arg (args, unsigned long int);
+	else if (cflags == DP_C_LONG_LONG)
+	  value = va_arg (args, unsigned long long);
 	else
 	  value = va_arg (args, unsigned int);
 	fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
@@ -337,6 +357,12 @@
 	  num = va_arg (args, long int *);
 	  *num = currlen;
         } 
+	else if (cflags == DP_C_LONG_LONG)
+        {
+	  long long *num;
+	  num = va_arg (args, long long *);
+          *num = currlen;
+        }
 	else 
 	{
 	  int *num;
@@ -747,9 +773,11 @@
     "%+22.33d",
     "%01.3d",
     "%4d",
+    "%lld",
+    "%qd",
     NULL
   };
-  long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
+  long long int_nums[] = { -1, 134, 91340, 341, 0203, 0, 9999999 };
   int x, y;
   int fail = 0;
   int num = 0;


More information about the openssh-unix-dev mailing list