]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - lib/vsprintf.c
eeprom: fix eeprom write procedure
[people/ms/u-boot.git] / lib / vsprintf.c
index e0f264850f7fa75bc6cbeaad2537d3fffc4a318d..dd8380b418c932ca0e0d2e8b80248d213ee047da 100644 (file)
@@ -166,6 +166,25 @@ unsigned long long simple_strtoull(const char *cp, char **endp,
        return result;
 }
 
+long trailing_strtoln(const char *str, const char *end)
+{
+       const char *p;
+
+       if (!end)
+               end = str + strlen(str);
+       for (p = end - 1; p > str; p--) {
+               if (!isdigit(*p))
+                       return simple_strtoul(p + 1, NULL, 10);
+       }
+
+       return -1;
+}
+
+long trailing_strtol(const char *str)
+{
+       return trailing_strtoln(str, NULL);
+}
+
 /* we use this so that we can do without the ctype library */
 #define is_digit(c)    ((c) >= '0' && (c) <= '9')
 
@@ -842,13 +861,47 @@ int sprintf(char *buf, const char *fmt, ...)
        return i;
 }
 
-void panic(const char *fmt, ...)
+int printf(const char *fmt, ...)
 {
        va_list args;
+       uint i;
+       char printbuffer[CONFIG_SYS_PBSIZE];
+
        va_start(args, fmt);
-       vprintf(fmt, args);
-       putc('\n');
+
+       /*
+        * For this to work, printbuffer must be larger than
+        * anything we ever want to print.
+        */
+       i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
        va_end(args);
+
+       /* Print the string */
+       puts(printbuffer);
+       return i;
+}
+
+int vprintf(const char *fmt, va_list args)
+{
+       uint i;
+       char printbuffer[CONFIG_SYS_PBSIZE];
+
+       /*
+        * For this to work, printbuffer must be larger than
+        * anything we ever want to print.
+        */
+       i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
+
+       /* Print the string */
+       puts(printbuffer);
+       return i;
+}
+
+static void panic_finish(void) __attribute__ ((noreturn));
+
+static void panic_finish(void)
+{
+       putc('\n');
 #if defined(CONFIG_PANIC_HANG)
        hang();
 #else
@@ -859,6 +912,21 @@ void panic(const char *fmt, ...)
                ;
 }
 
+void panic_str(const char *str)
+{
+       puts(str);
+       panic_finish();
+}
+
+void panic(const char *fmt, ...)
+{
+       va_list args;
+       va_start(args, fmt);
+       vprintf(fmt, args);
+       va_end(args);
+       panic_finish();
+}
+
 void __assert_fail(const char *assertion, const char *file, unsigned line,
                   const char *function)
 {
@@ -896,3 +964,19 @@ void print_grouped_ull(unsigned long long int_val, int digits)
                grab = 3;
        }
 }
+
+bool str2off(const char *p, loff_t *num)
+{
+       char *endptr;
+
+       *num = simple_strtoull(p, &endptr, 16);
+       return *p != '\0' && *endptr == '\0';
+}
+
+bool str2long(const char *p, ulong *num)
+{
+       char *endptr;
+
+       *num = simple_strtoul(p, &endptr, 16);
+       return *p != '\0' && *endptr == '\0';
+}