MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / GetFileImage

Function GetFileImage

BaseTools/Source/C/Common/CommonLib.c:156–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154
155
156EFI_STATUS
157GetFileImage (
158 IN CHAR8 *InputFileName,
159 OUT CHAR8 **InputFileImage,
160 OUT UINT32 *BytesRead
161 )
162/*++
163
164Routine Description:
165
166 This function opens a file and reads it into a memory buffer. The function
167 will allocate the memory buffer and returns the size of the buffer.
168
169Arguments:
170
171 InputFileName The name of the file to read.
172 InputFileImage A pointer to the memory buffer.
173 BytesRead The size of the memory buffer.
174
175Returns:
176
177 EFI_SUCCESS The function completed successfully.
178 EFI_INVALID_PARAMETER One of the input parameters was invalid.
179 EFI_ABORTED An error occurred.
180 EFI_OUT_OF_RESOURCES No resource to complete operations.
181
182--*/
183{
184 FILE *InputFile;
185 UINT32 FileSize;
186
187 //
188 // Verify input parameters.
189 //
190 if (InputFileName == NULL || strlen (InputFileName) == 0 || InputFileImage == NULL) {
191 return EFI_INVALID_PARAMETER;
192 }
193 //
194 // Open the file and copy contents into a memory buffer.
195 //
196 //
197 // Open the file
198 //
199 InputFile = fopen (LongFilePath (InputFileName), "rb");
200 if (InputFile == NULL) {
201 Error (NULL, 0, 0001, "Error opening the input file", InputFileName);
202 return EFI_ABORTED;
203 }
204 //
205 // Go to the end so that we can determine the file size
206 //
207 if (fseek (InputFile, 0, SEEK_END)) {
208 Error (NULL, 0, 0004, "Error reading the input file", InputFileName);
209 fclose (InputFile);
210 return EFI_ABORTED;
211 }
212 //
213 // Get the file size

Callers 3

GenFv.cFile · 0.85
GetMemoryFileFunction · 0.85
ParseSectionFunction · 0.85

Calls 8

fopenFunction · 0.85
fcloseFunction · 0.85
freadFunction · 0.85
LongFilePathFunction · 0.70
ErrorFunction · 0.70
strlenFunction · 0.50
mallocFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected