Debian Codegraph @

src/random_data.c

raw
1 /* Copyright 2009-2012 Thomas Schoebel-Theuer / 1&1 Internet AG
2 *
3 * Email: [email protected]
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #define _GNU_SOURCE
21 #include <config.h>
22
23 #include <stdio.h>
24
25 #ifdef STDC_HEADERS
26 # include <stdlib.h>
27 # include <stddef.h>
28 #else
29 # ifdef HAVE_STDLIB_H
30 # include <stdlib.h>
31 # endif
32 #endif
33
34 #ifdef HAVE_UNISTD_H
35 # include <unistd.h>
36 #endif
37
38 #if HAVE_DECL_RANDOM
39 # define TYPE long int
40 #else
41 # define TYPE int
42 # define random rand
43 #endif
44
45 /* Infinitely create random data on stdout, until some error occurs.
46 */
47
48 #define SIZE (1024 * 1024)
49
50 int main(int argc, char *argv[])
51 {
52 static char buf[SIZE];
53 int i;
54 int status;
55 long long count = 0;
56
57 do {
58 for (i = 0; i < SIZE / sizeof(TYPE); i++) {
59 TYPE *ptr = (void*)&buf[i * sizeof(TYPE)];
60 *ptr = random();
61 }
62
63 status = write(1, buf, sizeof(buf));
64 if (status > 0)
65 count += status;
66
67 } while (status == sizeof(buf));
68
69 fprintf(stderr,
70 "%s wrote %lld KiBytes (%lld MiBytes, %lld GiBytes)\n",
71 argv[0],
72 count / 1024,
73 count / (1024 * 1024),
74 count / (1024 * 1024 * 1024));
75 fflush(stderr);
76
77 return 0;
78 }