Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Unified Diff: host/lib/host_misc.c

Issue 6780008: Refactor crossystem to move x86-specific implementation to its own file. (Closed) Base URL: ssh://gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: post-pull Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « host/lib/crossystem.c ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « host/lib/crossystem.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698