| 256 | } |
| 257 | |
| 258 | EFI_STATUS |
| 259 | PutFileImage ( |
| 260 | IN CHAR8 *OutputFileName, |
| 261 | IN CHAR8 *OutputFileImage, |
| 262 | IN UINT32 BytesToWrite |
| 263 | ) |
| 264 | /*++ |
| 265 | |
| 266 | Routine Description: |
| 267 | |
| 268 | This function opens a file and writes OutputFileImage into the file. |
| 269 | |
| 270 | Arguments: |
| 271 | |
| 272 | OutputFileName The name of the file to write. |
| 273 | OutputFileImage A pointer to the memory buffer. |
| 274 | BytesToWrite The size of the memory buffer. |
| 275 | |
| 276 | Returns: |
| 277 | |
| 278 | EFI_SUCCESS The function completed successfully. |
| 279 | EFI_INVALID_PARAMETER One of the input parameters was invalid. |
| 280 | EFI_ABORTED An error occurred. |
| 281 | EFI_OUT_OF_RESOURCES No resource to complete operations. |
| 282 | |
| 283 | --*/ |
| 284 | { |
| 285 | FILE *OutputFile; |
| 286 | UINT32 BytesWrote; |
| 287 | |
| 288 | // |
| 289 | // Verify input parameters. |
| 290 | // |
| 291 | if (OutputFileName == NULL || strlen (OutputFileName) == 0 || OutputFileImage == NULL) { |
| 292 | return EFI_INVALID_PARAMETER; |
| 293 | } |
| 294 | // |
| 295 | // Open the file and copy contents into a memory buffer. |
| 296 | // |
| 297 | // |
| 298 | // Open the file |
| 299 | // |
| 300 | OutputFile = fopen (LongFilePath (OutputFileName), "wb"); |
| 301 | if (OutputFile == NULL) { |
| 302 | Error (NULL, 0, 0001, "Error opening the output file", OutputFileName); |
| 303 | return EFI_ABORTED; |
| 304 | } |
| 305 | |
| 306 | // |
| 307 | // Write all of the file contents. |
| 308 | // |
| 309 | BytesWrote = fwrite (OutputFileImage, sizeof (UINT8), BytesToWrite, OutputFile); |
| 310 | if (BytesWrote != sizeof (UINT8) * BytesToWrite) { |
| 311 | Error (NULL, 0, 0002, "Error writing the output file", OutputFileName); |
| 312 | fclose (OutputFile); |
| 313 | return EFI_ABORTED; |
| 314 | } |
| 315 | // |
no test coverage detected