summaryrefslogtreecommitdiffstats
path: root/src/core/vsprintf.c
diff options
context:
space:
mode:
authorMichael Brown2005-05-17 20:26:41 +0200
committerMichael Brown2005-05-17 20:26:41 +0200
commitff9104e0296e9b01733e04193130c60fcc5f5212 (patch)
tree61ef1dda1aa392621b169d7c03c0b9ab7c53bcd7 /src/core/vsprintf.c
parentChanged to 5.5 (diff)
downloadipxe-ff9104e0296e9b01733e04193130c60fcc5f5212.tar.gz
ipxe-ff9104e0296e9b01733e04193130c60fcc5f5212.tar.xz
ipxe-ff9104e0296e9b01733e04193130c60fcc5f5212.zip
Added errno, strerror and the "%m" printf metacharacter. These will allow
us to return proper PXE status codes, while simultaneously allowing for more consistent error reporting (complete with verbose error messages as a build-time option).
Diffstat (limited to 'src/core/vsprintf.c')
-rw-r--r--src/core/vsprintf.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/core/vsprintf.c b/src/core/vsprintf.c
index 414b4509..77373ccf 100644
--- a/src/core/vsprintf.c
+++ b/src/core/vsprintf.c
@@ -2,6 +2,7 @@
#include "if_ether.h" /* for ETH_ALEN */
#include "limits.h" /* for CHAR_BIT */
#include "console.h"
+#include "errno.h"
#include "vsprintf.h"
#define LONG_SHIFT ((int)((sizeof(unsigned long)*CHAR_BIT) - 4))
@@ -31,7 +32,8 @@ PRINTF and friends
**************************************************************************/
static int vsprintf(char *buf, const char *fmt, va_list args)
{
- char *p, *s;
+ const char *p;
+ char *s;
s = buf;
for ( ; *fmt != '\0'; ++fmt) {
if (*fmt != '%') {
@@ -49,8 +51,10 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
if (*fmt == 's') {
for(p = va_arg(args, char *); *p != '\0'; p++)
buf ? *s++ = *p : putchar(*p);
- }
- else { /* Length of item is bounded */
+ } else if (*fmt == 'm') {
+ for(p = strerror(errno); *p != '\0'; p++)
+ buf ? *s++ = *p : putchar(*p);
+ } else { /* Length of item is bounded */
char tmp[40], *q = tmp;
int alt = 0;
int shift = INT_SHIFT;
@@ -93,7 +97,7 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
*q++ = "0123456789ABCDEF"[(h >> shift) & 0xF] | ncase;
}
else if (*fmt == 'd') {
- char *r;
+ char *r, *t;
long i;
if (shift > INT_SHIFT) {
i = va_arg(args, long);
@@ -104,17 +108,17 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
*q++ = '-';
i = -i;
}
- p = q; /* save beginning of digits */
+ t = q; /* save beginning of digits */
do {
*q++ = '0' + (i % 10);
i /= 10;
} while (i);
/* reverse digits, stop in middle */
r = q; /* don't alter q */
- while (--r > p) {
+ while (--r > t) {
i = *r;
- *r = *p;
- *p++ = i;
+ *r = *t;
+ *t++ = i;
}
}
else if (*fmt == '@') {
@@ -129,7 +133,7 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
--q;
}
else if (*fmt == '!') {
- char *r;
+ const char *r;
p = va_arg(args, char *);
for (r = p + ETH_ALEN; p < r; ++p)
q += sprintf(q, "%hhX:", *p);