mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
38 lines
730 B
C
38 lines
730 B
C
/** @file
|
|
Copyright (c) 2020, PMheart. All rights reserved.
|
|
SPDX-License-Identifier: BSD-3-Clause
|
|
**/
|
|
|
|
#include <UserFile.h>
|
|
#include <Library/MemoryAllocationLib.h>
|
|
|
|
uint8_t *UserReadFile(const char *str, uint32_t *size) {
|
|
FILE *f = fopen(str, "rb");
|
|
|
|
if (!f) return NULL;
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
long fsize = ftell(f);
|
|
fseek(f, 0, SEEK_SET);
|
|
|
|
uint8_t *string = AllocatePool(fsize + 1);
|
|
if (fsize > 0 && fread(string, fsize, 1, f) != 1)
|
|
abort();
|
|
fclose(f);
|
|
|
|
string[fsize] = 0;
|
|
*size = fsize;
|
|
|
|
return string;
|
|
}
|
|
|
|
void UserWriteFile(const char *str, void *data, uint32_t size) {
|
|
FILE *Fh = fopen(str, "wb");
|
|
|
|
if (!Fh) abort();
|
|
|
|
if (fwrite (data, size, 1, Fh) != 1)
|
|
abort();
|
|
fclose(Fh);
|
|
}
|