OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. |
| 4 * |
| 5 * Host functions for verified boot. |
| 6 */ |
| 7 |
| 8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ |
| 9 |
| 10 #include <stdio.h> |
| 11 #include <stdlib.h> |
| 12 |
| 13 #include "host_common.h" |
| 14 |
| 15 #include "cryptolib.h" |
| 16 #include "utility.h" |
| 17 #include "vboot_common.h" |
| 18 |
| 19 |
| 20 uint8_t* ReadFile(const char* filename, uint64_t* size) { |
| 21 FILE* f; |
| 22 uint8_t* buf; |
| 23 |
| 24 f = fopen(filename, "rb"); |
| 25 if (!f) { |
| 26 debug("Unable to open file %s\n", filename); |
| 27 return NULL; |
| 28 } |
| 29 |
| 30 fseek(f, 0, SEEK_END); |
| 31 *size = ftell(f); |
| 32 rewind(f); |
| 33 |
| 34 buf = Malloc(*size); |
| 35 if (!buf) { |
| 36 fclose(f); |
| 37 return NULL; |
| 38 } |
| 39 |
| 40 if(1 != fread(buf, *size, 1, f)) { |
| 41 debug("Unable to read from file %s\n", filename); |
| 42 fclose(f); |
| 43 Free(buf); |
| 44 return NULL; |
| 45 } |
| 46 |
| 47 fclose(f); |
| 48 return buf; |
| 49 } |
OLD | NEW |