diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2017-05-05 11:31:34 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-05-05 11:31:34 +0200 |
commit | e63f9a85226b1520a5881da7e7fef82446deb879 (patch) | |
tree | cdc1d521e9338d24af1c0a98c6177587a771b33e /lib | |
parent | 337bf5f7eb243fb909f045950e8b6f402e5a0f8e (diff) | |
parent | b876c2b7394f9d5258e6b73f684741c88fa41f23 (diff) | |
download | barebox-e63f9a85226b1520a5881da7e7fef82446deb879.tar.gz barebox-e63f9a85226b1520a5881da7e7fef82446deb879.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/readline_simple.c | 13 | ||||
-rw-r--r-- | lib/strtox.c | 54 | ||||
-rw-r--r-- | lib/xfuncs.c | 32 |
3 files changed, 55 insertions, 44 deletions
diff --git a/lib/readline_simple.c b/lib/readline_simple.c index c2960665fb..c4d3d240e5 100644 --- a/lib/readline_simple.c +++ b/lib/readline_simple.c @@ -57,19 +57,6 @@ int readline (const char *prompt, char *line, int len) col = plen; for (;;) { -#ifdef CONFIG_BOOT_RETRY_TIME - while (!tstc()) { /* while no incoming data */ - if (retry_time >= 0 && get_ticks() > endtime) - return (-2); /* timed out */ - } -#endif - -#ifdef CONFIG_SHOW_ACTIVITY - while (!tstc()) { - extern void show_activity(int arg); - show_activity(0); - } -#endif c = getchar(); /* diff --git a/lib/strtox.c b/lib/strtox.c index cfe61240cc..3bb6b0ef89 100644 --- a/lib/strtox.c +++ b/lib/strtox.c @@ -1,67 +1,75 @@ #include <common.h> #include <linux/ctype.h> -unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) +unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) { - unsigned long result = 0,value; + unsigned long result = 0, value; if (*cp == '0') { cp++; + if ((*cp == 'x') && isxdigit(cp[1])) { base = 16; cp++; } - if (!base) { + + if (!base) base = 8; - } } - if (!base) { + + if (!base) base = 10; - } - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) - ? toupper(*cp) : *cp)-'A'+10) < base) { - result = result*base + value; + + while (isxdigit(*cp) && (value = isdigit(*cp) ? + *cp - '0' : toupper(*cp) - 'A' + 10) < base) { + result = result * base + value; cp++; } + if (endp) *endp = (char *)cp; + return result; } EXPORT_SYMBOL(simple_strtoul); -long simple_strtol(const char *cp,char **endp,unsigned int base) +long simple_strtol(const char *cp, char **endp, unsigned int base) { - if(*cp=='-') - return -simple_strtoul(cp+1,endp,base); - return simple_strtoul(cp,endp,base); + if (*cp == '-') + return -simple_strtoul(cp + 1, endp, base); + + return simple_strtoul(cp, endp, base); } EXPORT_SYMBOL(simple_strtol); -unsigned long long simple_strtoull (const char *cp, char **endp, unsigned int base) +unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) { unsigned long long result = 0, value; if (*cp == '0') { cp++; - if ((*cp == 'x') && isxdigit (cp[1])) { + + if ((*cp == 'x') && isxdigit(cp[1])) { base = 16; cp++; } - if (!base) { + + if (!base) base = 8; - } } - if (!base) { + + if (!base) base = 10; - } - while (isxdigit (*cp) && (value = isdigit (*cp) - ? *cp - '0' - : (islower (*cp) ? toupper (*cp) : *cp) - 'A' + 10) < base) { + + while (isxdigit(*cp) && (value = isdigit(*cp) ? + *cp - '0' : toupper(*cp) - 'A' + 10) < base) { result = result * base + value; cp++; } + if (endp) - *endp = (char *) cp; + *endp = (char *)cp; + return result; } EXPORT_SYMBOL(simple_strtoull); diff --git a/lib/xfuncs.c b/lib/xfuncs.c index 1dc2ea92d8..1bcaa5e10e 100644 --- a/lib/xfuncs.c +++ b/lib/xfuncs.c @@ -18,18 +18,30 @@ * GNU General Public License for more details. * */ +#define pr_fmt(fmt) "xfuncs: " fmt #include <common.h> #include <malloc.h> #include <module.h> #include <wchar.h> +static void __noreturn enomem_panic(size_t size) +{ + pr_emerg("out of memory\n"); + if (size) + pr_emerg("Unable to allocate %d bytes\n", size); + + malloc_stats(); + + panic("out of memory"); +} + void *xmalloc(size_t size) { void *p = NULL; if (!(p = malloc(size))) - panic("ERROR: out of memory\n"); + enomem_panic(size); return p; } @@ -40,7 +52,7 @@ void *xrealloc(void *ptr, size_t size) void *p = NULL; if (!(p = realloc(ptr, size))) - panic("ERROR: out of memory\n"); + enomem_panic(size); return p; } @@ -63,7 +75,7 @@ char *xstrdup(const char *s) p = strdup(s); if (!p) - panic("ERROR: out of memory\n"); + enomem_panic(strlen(s) + 1); return p; } @@ -95,7 +107,8 @@ void* xmemalign(size_t alignment, size_t bytes) { void *p = memalign(alignment, bytes); if (!p) - panic("ERROR: out of memory\n"); + enomem_panic(bytes); + return p; } EXPORT_SYMBOL(xmemalign); @@ -116,7 +129,7 @@ char *xvasprintf(const char *fmt, va_list ap) p = bvasprintf(fmt, ap); if (!p) - panic("ERROR: out of memory\n"); + enomem_panic(0); return p; } EXPORT_SYMBOL(xvasprintf); @@ -139,7 +152,8 @@ wchar_t *xstrdup_wchar(const wchar_t *s) wchar_t *p = strdup_wchar(s); if (!p) - panic("ERROR: out of memory\n"); + enomem_panic((wcslen(s) + 1) * sizeof(wchar_t)); + return p; } EXPORT_SYMBOL(xstrdup_wchar); @@ -149,7 +163,8 @@ wchar_t *xstrdup_char_to_wchar(const char *s) wchar_t *p = strdup_char_to_wchar(s); if (!p) - panic("ERROR: out of memory\n"); + enomem_panic((strlen(s) + 1) * sizeof(wchar_t)); + return p; } EXPORT_SYMBOL(xstrdup_char_to_wchar); @@ -159,7 +174,8 @@ char *xstrdup_wchar_to_char(const wchar_t *s) char *p = strdup_wchar_to_char(s); if (!p) - panic("ERROR: out of memory\n"); + enomem_panic((wcslen(s) + 1) * sizeof(wchar_t)); + return p; } EXPORT_SYMBOL(xstrdup_wchar_to_char); |