]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - lib/vsprintf.c
ipv6: AF_INET6 link address family
[net-next-2.6.git] / lib / vsprintf.c
index 4ee19d0d3910b36ad15f88688db46d5d1249fa61..c150d3dafff4a4152f085ff1ae33ae0f122f25f6 100644 (file)
@@ -146,19 +146,16 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
 {
        char *tail;
        unsigned long val;
-       size_t len;
 
        *res = 0;
-       len = strlen(cp);
-       if (len == 0)
+       if (!*cp)
                return -EINVAL;
 
        val = simple_strtoul(cp, &tail, base);
        if (tail == cp)
                return -EINVAL;
 
-       if ((*tail == '\0') ||
-               ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
+       if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
                *res = val;
                return 0;
        }
@@ -220,18 +217,15 @@ int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res)
 {
        char *tail;
        unsigned long long val;
-       size_t len;
 
        *res = 0;
-       len = strlen(cp);
-       if (len == 0)
+       if (!*cp)
                return -EINVAL;
 
        val = simple_strtoull(cp, &tail, base);
        if (tail == cp)
                return -EINVAL;
-       if ((*tail == '\0') ||
-               ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
+       if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
                *res = val;
                return 0;
        }
@@ -994,8 +988,15 @@ static noinline_for_stack
 char *pointer(const char *fmt, char *buf, char *end, void *ptr,
              struct printf_spec spec)
 {
-       if (!ptr)
+       if (!ptr) {
+               /*
+                * Print (null) with the same width as a pointer so it makes
+                * tabular output look nice.
+                */
+               if (spec.field_width == -1)
+                       spec.field_width = 2 * sizeof(void *);
                return string(buf, end, "(null)", spec);
+       }
 
        switch (*fmt) {
        case 'F':
@@ -1037,7 +1038,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
        }
        spec.flags |= SMALL;
        if (spec.field_width == -1) {
-               spec.field_width = 2*sizeof(void *);
+               spec.field_width = 2 * sizeof(void *);
                spec.flags |= ZEROPAD;
        }
        spec.base = 16;
@@ -1503,7 +1504,7 @@ EXPORT_SYMBOL(snprintf);
  * @...: Arguments for the format string
  *
  * The return value is the number of characters written into @buf not including
- * the trailing '\0'. If @size is <= 0 the function returns 0.
+ * the trailing '\0'. If @size is == 0 the function returns 0.
  */
 
 int scnprintf(char *buf, size_t size, const char *fmt, ...)
@@ -1515,7 +1516,11 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...)
        i = vsnprintf(buf, size, fmt, args);
        va_end(args);
 
-       return (i >= size) ? (size - 1) : i;
+       if (likely(i < size))
+               return i;
+       if (size != 0)
+               return size - 1;
+       return 0;
 }
 EXPORT_SYMBOL(scnprintf);