[2082] * kern/misc.c (grub_ltoa): New function.

"David S. Miller" <[email protected]>
Newsgroups gmane.comp.boot-loaders.grub.cvs
Message-ID <[email protected]>
Revision: 2082
          http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=2082
Author:   davem
Date:     2009-04-11 11:48:34 +0000 (Sat, 11 Apr 2009)
Log Message:
-----------
	* kern/misc.c (grub_ltoa): New function.
	(grub_vsprintf): Use it to format 'long' integers.

Modified Paths:
--------------
    trunk/grub2/ChangeLog
    trunk/grub2/kern/misc.c

Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog	2009-04-11 09:40:39 UTC (rev 2081)
+++ trunk/grub2/ChangeLog	2009-04-11 11:48:34 UTC (rev 2082)
@@ -33,6 +33,9 @@
 	* boot/sparc64/ieee1275/boot.S: Likewise.
 	* boot/sparc64/ieee1275/diskboot.S: Likewise.
 
+	* kern/misc.c (grub_ltoa): New function.
+	(grub_vsprintf): Use it to format 'long' integers.
+
 2009-04-10  David S. Miller  <[email protected]>
 
 	* disk/ieee1275/nand.c (grub_nand_open): All ieee1275 call arg

Modified: trunk/grub2/kern/misc.c
===================================================================
--- trunk/grub2/kern/misc.c	2009-04-11 09:40:39 UTC (rev 2081)
+++ trunk/grub2/kern/misc.c	2009-04-11 11:48:34 UTC (rev 2082)
@@ -590,6 +590,31 @@
   return p;
 }
 
+static char *
+grub_ltoa (char *str, int c, unsigned long n)
+{
+  unsigned long base = (c == 'x') ? 16 : 10;
+  char *p;
+
+  if ((long) n < 0 && c == 'd')
+    {
+      n = (unsigned) (-((long) n));
+      *str++ = '-';
+    }
+
+  p = str;
+  do
+    {
+      unsigned long d = n % base;
+      *p++ = (d > 9) ? d + 'a' - 10 : d + '0';
+    }
+  while (n /= base);
+  *p = 0;
+
+  grub_reverse (str);
+  return p;
+}
+
 /* Divide N by D, return the quotient, and store the remainder in *R.  */
 grub_uint64_t
 grub_divmod64 (grub_uint64_t n, grub_uint32_t d, grub_uint32_t *r)
@@ -790,12 +815,14 @@
 		  ll = va_arg (args, long long);
 		  grub_lltoa (tmp, c, ll);
 		}
+	      else if (longfmt)
+		{
+		  long l = va_arg (args, long);
+		  grub_ltoa (tmp, c, l);
+		}
 	      else
 		{
-		  if (longfmt)
-		    n = va_arg (args, long);
-		  else
-		    n = va_arg (args, int);
+		  n = va_arg (args, int);
 		  grub_itoa (tmp, c, n);
 		}
 	      if (! rightfill && grub_strlen (tmp) < format1)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.