// Pass in a zero-size buffer to find the required buffer size.
Status = gRT->GetVariable (
// If variable exists, the Status should be EFI_BUFFER_TOO_SMALL and
// BufferSize has been updated.
if (Status != EFI_BUFFER_TOO_SMALL) {
// Allocate the buffer according to updated BufferSize.
Buffer = AllocateZeroPool (BufferSize);
// Read variable into the allocated buffer.
Status = gRT->GetVariable (
if (EFI_ERROR (Status)) {
// TODO: Process of retrieved variable can be added here.
// Now write back the processed variable.
Status = gRT->SetVariable (
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS |
EFI_VARIABLE_NON_VOLATILE,
ASSERT_EFI_ERROR (Status);