| Index: host/lib/host_misc.c
|
| diff --git a/host/lib/host_misc.c b/host/lib/host_misc.c
|
| index 91eaea25d56ccaddd9ec7736f308f3215f44ceb3..f8dd9b8f451336235f9ff82dbf3bb7e571fa89be 100644
|
| --- a/host/lib/host_misc.c
|
| +++ b/host/lib/host_misc.c
|
| @@ -9,6 +9,7 @@
|
|
|
| #include <stdio.h>
|
| #include <stdlib.h>
|
| +#include <string.h>
|
| #include <unistd.h>
|
|
|
| #include "host_common.h"
|
| @@ -18,6 +19,13 @@
|
| #include "vboot_common.h"
|
|
|
|
|
| +char* StrCopy(char* dest, const char* src, int dest_size) {
|
| + strncpy(dest, src, dest_size);
|
| + dest[dest_size - 1] = '\0';
|
| + return dest;
|
| +}
|
| +
|
| +
|
| uint8_t* ReadFile(const char* filename, uint64_t* size) {
|
| FILE* f;
|
| uint8_t* buf;
|
| @@ -50,6 +58,45 @@ uint8_t* ReadFile(const char* filename, uint64_t* size) {
|
| }
|
|
|
|
|
| +char* ReadFileString(char* dest, int size, const char* filename) {
|
| + char* got;
|
| + FILE* f;
|
| +
|
| + f = fopen(filename, "rt");
|
| + if (!f)
|
| + return NULL;
|
| +
|
| + got = fgets(dest, size, f);
|
| + fclose(f);
|
| + return got;
|
| +}
|
| +
|
| +
|
| +int ReadFileInt(const char* filename) {
|
| + char buf[64];
|
| + int value;
|
| + char* e = NULL;
|
| +
|
| + if (!ReadFileString(buf, sizeof(buf), filename))
|
| + return -1;
|
| +
|
| + /* Convert to integer. Allow characters after the int ("123 blah"). */
|
| + value = strtol(buf, &e, 0);
|
| + if (e == buf)
|
| + return -1; /* No characters consumed, so conversion failed */
|
| +
|
| + return value;
|
| +}
|
| +
|
| +
|
| +int ReadFileBit(const char* filename, int bitmask) {
|
| + int value = ReadFileInt(filename);
|
| + if (value == -1)
|
| + return -1;
|
| + else return (value & bitmask ? 1 : 0);
|
| +}
|
| +
|
| +
|
| int WriteFile(const char* filename, const void *data, uint64_t size) {
|
| FILE *f = fopen(filename, "wb");
|
| if (!f) {
|
|
|