aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMarat Dukhan <marat@fb.com>2018-04-19 12:29:15 -0700
committerMarat Dukhan <marat@fb.com>2018-04-19 12:29:15 -0700
commitcb9ae9c9a5be95f5a1abaa5f27d1b2e0362b58f2 (patch)
tree551dd468aea7a6f62fa595d26f35992a00cdb0e7 /tools
parentdca6828c3e50f172b61cff22c8e996e929ea723c (diff)
downloadcpuinfo-cb9ae9c9a5be95f5a1abaa5f27d1b2e0362b58f2.tar.gz
Add tool to dump /proc/cpuinfo under AArch32 on AArch64 systems
Diffstat (limited to 'tools')
-rw-r--r--tools/cpuinfo-dump.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/cpuinfo-dump.c b/tools/cpuinfo-dump.c
new file mode 100644
index 0000000..5b5228a
--- /dev/null
+++ b/tools/cpuinfo-dump.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+
+#define BUFFER_SIZE 4096
+char buffer[BUFFER_SIZE];
+
+#define CPUINFO_PATH "/proc/cpuinfo"
+
+int main(int argc, char** argv) {
+ int file = open(CPUINFO_PATH, O_RDONLY);
+ if (file == -1) {
+ fprintf(stderr, "Error: failed to open %s: %s\n", CPUINFO_PATH, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ /* Only used for error reporting */
+ size_t position = 0;
+ char* data_start = buffer;
+ ssize_t bytes_read;
+ do {
+ bytes_read = read(file, buffer, BUFFER_SIZE);
+ if (bytes_read < 0) {
+ fprintf(stderr, "Error: failed to read file %s at position %zu: %s\n",
+ CPUINFO_PATH, position, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ position += (size_t) bytes_read;
+ if (bytes_read > 0) {
+ fwrite(buffer, 1, (size_t) bytes_read, stdout);
+ }
+ } while (bytes_read != 0);
+
+ if (close(file) != 0) {
+ fprintf(stderr, "Error: failed to close %s: %s\n", CPUINFO_PATH, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ return EXIT_SUCCESS;
+}