proc: add seq_put_decimal_ull_width to speed up /proc/pid/smaps
[sfrench/cifs-2.6.git] / lib / vsprintf.c
index 89f8a4a4b770d6c5b56c90cbc9ea1d4fd93d5623..30c0cb8cc9bce78089cb6ad48bcb6b3d5d02e6b2 100644 (file)
@@ -336,7 +336,7 @@ char *put_dec(char *buf, unsigned long long n)
  *
  * If speed is not important, use snprintf(). It's easy to read the code.
  */
-int num_to_str(char *buf, int size, unsigned long long num)
+int num_to_str(char *buf, int size, unsigned long long num, unsigned int width)
 {
        /* put_dec requires 2-byte alignment of the buffer. */
        char tmp[sizeof(num) * 3] __aligned(2);
@@ -350,11 +350,21 @@ int num_to_str(char *buf, int size, unsigned long long num)
                len = put_dec(tmp, num) - tmp;
        }
 
-       if (len > size)
+       if (len > size || width > size)
                return 0;
+
+       if (width > len) {
+               width = width - len;
+               for (idx = 0; idx < width; idx++)
+                       buf[idx] = ' ';
+       } else {
+               width = 0;
+       }
+
        for (idx = 0; idx < len; ++idx)
-               buf[idx] = tmp[len - idx - 1];
-       return len;
+               buf[idx + width] = tmp[len - idx - 1];
+
+       return len + width;
 }
 
 #define SIGN   1               /* unsigned/signed, must be 1 */