-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Jones <pjones@redhat.com>
- Loading branch information
Showing
5 changed files
with
190 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* errlog.c | ||
* Copyright 2017 Peter Jones <pjones@redhat.com> | ||
* | ||
* Distributed under terms of the GPLv3 license. | ||
*/ | ||
|
||
#include "shim.h" | ||
|
||
#ifdef LogError | ||
#undef LogError | ||
#endif | ||
|
||
static CHAR16 **errs = NULL; | ||
static UINTN nerrs = 0; | ||
|
||
EFI_STATUS | ||
VLogError(const char *file, int line, const char *func, CHAR16 *fmt, va_list args) | ||
{ | ||
va_list args2; | ||
UINTN size = 0, size2; | ||
CHAR16 **newerrs; | ||
|
||
size = SPrint(NULL, 0, L"%a:%d %a() ", file, line, func); | ||
va_copy(args2, args); | ||
size2 = VSPrint(NULL, 0, fmt, args2); | ||
va_end(args2); | ||
|
||
newerrs = ReallocatePool(errs, (nerrs + 1) * sizeof(*errs), | ||
(nerrs + 3) * sizeof(*errs)); | ||
if (!newerrs) | ||
return EFI_OUT_OF_RESOURCES; | ||
|
||
newerrs[nerrs] = AllocatePool(size*2+2); | ||
if (!newerrs[nerrs]) | ||
return EFI_OUT_OF_RESOURCES; | ||
newerrs[nerrs+1] = AllocatePool(size2*2+2); | ||
if (!newerrs[nerrs+1]) | ||
return EFI_OUT_OF_RESOURCES; | ||
|
||
SPrint(newerrs[nerrs], size*2+2, L"%a:%d %a() ", file, line, func); | ||
va_copy(args2, args); | ||
VSPrint(newerrs[nerrs+1], size2*2+2, fmt, args2); | ||
va_end(args2); | ||
|
||
nerrs += 2; | ||
newerrs[nerrs] = NULL; | ||
errs = newerrs; | ||
|
||
return EFI_SUCCESS; | ||
} | ||
|
||
EFI_STATUS | ||
LogError(const char *file, int line, const char *func, CHAR16 *fmt, ...) | ||
{ | ||
va_list args; | ||
EFI_STATUS status; | ||
|
||
va_start(args, fmt); | ||
status = VLogError(file, line, func, fmt, args); | ||
va_end(args); | ||
|
||
return status; | ||
} | ||
|
||
VOID | ||
PrintErrors(VOID) | ||
{ | ||
UINTN i; | ||
|
||
if (!verbose) | ||
return; | ||
|
||
for (i = 0; i < nerrs; i++) | ||
Print(L"%s", errs[i]); | ||
} | ||
|
||
VOID | ||
ClearErrors(VOID) | ||
{ | ||
UINTN i; | ||
|
||
for (i = 0; i < nerrs; i++) | ||
FreePool(errs[i]); | ||
FreePool(errs); | ||
nerrs = 0; | ||
errs = NULL; | ||
} | ||
|
||
// vim:fenc=utf-8:tw=75 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.