| 154 | |
| 155 | |
| 156 | EFI_STATUS |
| 157 | GetFileImage ( |
| 158 | IN CHAR8 *InputFileName, |
| 159 | OUT CHAR8 **InputFileImage, |
| 160 | OUT UINT32 *BytesRead |
| 161 | ) |
| 162 | /*++ |
| 163 | |
| 164 | Routine 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 | |
| 169 | Arguments: |
| 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 | |
| 175 | Returns: |
| 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 |