How do I return a value and print it out?

155 Views Asked by At

Hello I am currently programming a UEFI bootloader with GNU-EFI and I am just about to program a small config system I have tested it so far and it works, but now I did not want to have everything in one file and split it into several files. Now I have the problem that in my File.c file in the ReadFile function somehow the buffer is not returned. I already checked if the buffer contains anything at all and t does. Hope someone can help me.

File.c

UINT8 *ReadFile(EFI_FILE_HANDLE Volume, CHAR16 *FileName) {

    // Declare variables
    EFI_STATUS Status;
    EFI_FILE_HANDLE FileHandle;
    UINT64 ReadSize;
    UINT8 *Buffer;

    // Open the file
    Status = uefi_call_wrapper(
        Volume->Open,
        5,
        Volume,
        &FileHandle,
        FileName,
        EFI_FILE_MODE_READ,
        EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM
    );
    if(EFI_ERROR(Status)) {
        Print(L"Could not open file! Reason: %r\n", Status);
    }

    // Read the contents of the file
    ReadSize = FileSize(FileHandle);
    Buffer = AllocatePool(ReadSize);

    Status = uefi_call_wrapper(
        FileHandle->Read,
        3,
        FileHandle,
        &ReadSize,
        Buffer
    );
    if(EFI_ERROR(Status)) {
        Print(L"Could not read file! Reason: %r\n", Status);
    }

    // Close the file
    Status = uefi_call_wrapper(
        FileHandle->Close,
        1,
        FileHandle
    );
    if(EFI_ERROR(Status)) {
        Print(L"Could not close file! Reason: %r\n", Status);
    }

    return Buffer;
}

Main.c

    UINT8 *Buffer = ReadFile(Volume, FileName);

    Print(L"File content:\n%a\n", Buffer);
0

There are 0 best solutions below