Created
November 6, 2012 02:54
-
-
Save mmitou/4022267 to your computer and use it in GitHub Desktop.
/dev/randomから読み込み
This file contains hidden or 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
| #include <stdio.h> | |
| #include <errno.h> | |
| #include <fcntl.h> | |
| #include <sys/types.h> | |
| #include <sys/stat.h> | |
| int main() { | |
| const int fd = open("/dev/random", | |
| O_RDONLY); | |
| int i; | |
| if(fd < 0) { | |
| perror("open /dev/radom: "); | |
| return 1; | |
| } | |
| for(i = 0; i < 10; ++i) { | |
| int buf = 0; | |
| const ssize_t size = read(fd, &buf, sizeof(buf)); | |
| if(size == sizeof(int)) { | |
| printf("%d: %x\n", i, buf); | |
| } else { | |
| perror("read fail:"); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment