author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:00 +0100 | |
changeset 8 | 96d16dfe787a |
parent 0 | af501b0c1716 |
child 9 | c3fecc82ade6 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* $Id: urandom.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $ |
|
3 |
* $Source: /development/c/demos/urandom.c,v $ |
|
4 |
* |
|
5 |
*/ |
|
6 |
||
7 |
#include <stdio.h> |
|
8 |
#include <stdlib.h> |
|
9 |
#include <fcntl.h> |
|
10 |
#include <unistd.h> |
|
11 |
||
12 |
int compare (unsigned char *a, unsigned char *b) |
|
13 |
{ |
|
14 |
if (*a > *b) |
|
15 |
return 1; |
|
16 |
return -1; |
|
17 |
} |
|
18 |
||
19 |
int main (int argc, char **argv) |
|
20 |
{ |
|
21 |
int i; |
|
22 |
int elements; |
|
23 |
int fd; |
|
24 |
unsigned char numbers[256] = { 0 }; |
|
25 |
||
26 |
fd = open ("/dev/urandom", O_RDONLY); |
|
27 |
if (fd == -1) |
|
28 |
return EXIT_FAILURE; |
|
29 |
||
30 |
elements = read (fd, numbers, 255); |
|
31 |
numbers[elements] = 0; |
|
32 |
||
33 |
qsort (numbers, elements, sizeof (unsigned char), (void *)&compare); |
|
34 |
||
35 |
for (i = 0; i < elements; i++) { |
|
36 |
printf ("Number: %d\n", numbers[i]); |
|
37 |
} |
|
38 |
||
39 |
close (fd); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
40 |
|
0 | 41 |
return EXIT_SUCCESS; |
42 |
} |