mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-19 19:34:35 +00:00
lib: Support printing an error string
It is often useful to show an error code to give the user a clue as to what went wrong. When error strings are compiled into U-Boot it is possible to show a message as well. But at present it is not very convenient, since code must check if the error strings are present, then obtain the error string and use it in a printf() string. Add a %dE option which shows an error code along with an error string, if available. This makes it easy to show one or both. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
057c567fb5
commit
7f33194132
1 changed files with 12 additions and 0 deletions
|
@ -145,6 +145,7 @@ static noinline char *put_dec(char *buf, uint64_t num)
|
||||||
#define LEFT 16 /* left justified */
|
#define LEFT 16 /* left justified */
|
||||||
#define SMALL 32 /* Must be 32 == 0x20 */
|
#define SMALL 32 /* Must be 32 == 0x20 */
|
||||||
#define SPECIAL 64 /* 0x */
|
#define SPECIAL 64 /* 0x */
|
||||||
|
#define ERRSTR 128 /* %dE showing error string if enabled */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Macro to add a new character to our output string, but only if it will
|
* Macro to add a new character to our output string, but only if it will
|
||||||
|
@ -678,6 +679,8 @@ repeat:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
|
if (fmt[1] == 'E')
|
||||||
|
flags |= ERRSTR;
|
||||||
case 'i':
|
case 'i':
|
||||||
flags |= SIGN;
|
flags |= SIGN;
|
||||||
case 'u':
|
case 'u':
|
||||||
|
@ -712,6 +715,15 @@ repeat:
|
||||||
}
|
}
|
||||||
str = number(str, end, num, base, field_width, precision,
|
str = number(str, end, num, base, field_width, precision,
|
||||||
flags);
|
flags);
|
||||||
|
if (IS_ENABLED(CONFIG_ERRNO_STR) && (flags & ERRSTR)) {
|
||||||
|
const char *p;
|
||||||
|
|
||||||
|
ADDCH(str, ':');
|
||||||
|
ADDCH(str, ' ');
|
||||||
|
for (p = errno_str(num); *p; p++)
|
||||||
|
ADDCH(str, *p);
|
||||||
|
fmt++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue