OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 * | 4 * |
5 * Host functions for verified boot. | 5 * Host functions for verified boot. |
6 */ | 6 */ |
7 | 7 |
8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ | 8 /* TODO: change all 'return 0', 'return 1' into meaningful return codes */ |
9 | 9 |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
| 12 #include <unistd.h> |
12 | 13 |
13 #include "host_common.h" | 14 #include "host_common.h" |
14 | 15 |
15 #include "cryptolib.h" | 16 #include "cryptolib.h" |
16 #include "utility.h" | 17 #include "utility.h" |
17 #include "vboot_common.h" | 18 #include "vboot_common.h" |
18 | 19 |
19 | 20 |
20 uint8_t* ReadFile(const char* filename, uint64_t* size) { | 21 uint8_t* ReadFile(const char* filename, uint64_t* size) { |
21 FILE* f; | 22 FILE* f; |
(...skipping 18 matching lines...) Expand all Loading... |
40 if(1 != fread(buf, *size, 1, f)) { | 41 if(1 != fread(buf, *size, 1, f)) { |
41 debug("Unable to read from file %s\n", filename); | 42 debug("Unable to read from file %s\n", filename); |
42 fclose(f); | 43 fclose(f); |
43 Free(buf); | 44 Free(buf); |
44 return NULL; | 45 return NULL; |
45 } | 46 } |
46 | 47 |
47 fclose(f); | 48 fclose(f); |
48 return buf; | 49 return buf; |
49 } | 50 } |
| 51 |
| 52 |
| 53 int WriteFile(const char* filename, const void *data, uint64_t size) { |
| 54 FILE *f = fopen(filename, "wb"); |
| 55 if (!f) { |
| 56 debug("Unable to open file %s\n", filename); |
| 57 return 1; |
| 58 } |
| 59 |
| 60 if (1 != fwrite(data, size, 1, f)) { |
| 61 debug("Unable to write to file %s\n", filename); |
| 62 fclose(f); |
| 63 unlink(filename); /* Delete any partial file */ |
| 64 } |
| 65 |
| 66 fclose(f); |
| 67 return 0; |
| 68 } |
OLD | NEW |