| 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 * Utility functions for file and key handling. | 5 * Utility functions for file and key handling. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "file_keys.h" | 8 #include "file_keys.h" |
| 9 | 9 |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 int fd; | 23 int fd; |
| 24 struct stat stat_fd; | 24 struct stat stat_fd; |
| 25 uint8_t* buf = NULL; | 25 uint8_t* buf = NULL; |
| 26 | 26 |
| 27 if ((fd = open(input_file, O_RDONLY)) == -1) { | 27 if ((fd = open(input_file, O_RDONLY)) == -1) { |
| 28 debug("Couldn't open file.\n"); | 28 debug("Couldn't open file.\n"); |
| 29 return NULL; | 29 return NULL; |
| 30 } | 30 } |
| 31 | 31 |
| 32 if (-1 == fstat(fd, &stat_fd)) { | 32 if (-1 == fstat(fd, &stat_fd)) { |
| 33 debug("Couldn't stat file\n"); | 33 debug("Couldn't stat file.\n"); |
| 34 return NULL; | 34 return NULL; |
| 35 } | 35 } |
| 36 *len = stat_fd.st_size; | 36 *len = stat_fd.st_size; |
| 37 | 37 |
| 38 buf = (uint8_t*) Malloc(*len); | 38 buf = (uint8_t*) Malloc(*len); |
| 39 if (!buf) | 39 if (!buf) { |
| 40 error("Couldn't allocate %ld bytes.\n", *len); |
| 40 return NULL; | 41 return NULL; |
| 42 } |
| 41 | 43 |
| 42 if (*len != read(fd, buf, *len)) { | 44 if (*len != read(fd, buf, *len)) { |
| 43 debug("Couldn't read file into a buffer.\n"); | 45 debug("Couldn't read file into a buffer.\n"); |
| 44 return NULL; | 46 return NULL; |
| 45 } | 47 } |
| 46 | 48 |
| 47 close(fd); | 49 close(fd); |
| 48 return buf; | 50 return buf; |
| 49 } | 51 } |
| 50 | 52 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 if (fread(signature, signature_size, 1, cmd_out) != 1) { | 112 if (fread(signature, signature_size, 1, cmd_out) != 1) { |
| 111 debug("Couldn't read signature.\n"); | 113 debug("Couldn't read signature.\n"); |
| 112 pclose(cmd_out); | 114 pclose(cmd_out); |
| 113 Free(signature); | 115 Free(signature); |
| 114 return NULL; | 116 return NULL; |
| 115 } | 117 } |
| 116 | 118 |
| 117 pclose(cmd_out); | 119 pclose(cmd_out); |
| 118 return signature; | 120 return signature; |
| 119 } | 121 } |
| OLD | NEW |