mirror of
https://github.com/ipxe/ipxe
synced 2025-12-26 09:32:33 +03:00
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).
This commit is contained in:
29
src/core/errno.c
Normal file
29
src/core/errno.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "errno.h"
|
||||
#include "vsprintf.h"
|
||||
|
||||
/* Global "last error" number */
|
||||
int errno;
|
||||
|
||||
static struct errortab errortab_start[0] __table_start(errortab);
|
||||
static struct errortab errortab_end[0] __table_end(errortab);
|
||||
|
||||
/*
|
||||
* Retrieve string representation of error number.
|
||||
*
|
||||
* If error not found in the error table, generate a generic "Error
|
||||
* 0x0000" message.
|
||||
*
|
||||
*/
|
||||
const char * strerror ( int errno ) {
|
||||
static char *generic_message = "Error 0x0000";
|
||||
struct errortab *errortab;
|
||||
|
||||
for ( errortab = errortab_start ; errortab < errortab_end ;
|
||||
errortab++ ) {
|
||||
if ( errortab->errno == errno )
|
||||
return errortab->text;
|
||||
}
|
||||
|
||||
sprintf ( generic_message + 8, "%hx", errno );
|
||||
return generic_message;
|
||||
}
|
||||
Reference in New Issue
Block a user