forked from pytorch/cpuinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool to dump /proc/cpuinfo under AArch32 on AArch64 systems
- Loading branch information
Marat Dukhan
committed
Apr 19, 2018
1 parent
dca6828
commit cb9ae9c
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |