Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / util / garbage-gen.c
blobccba1bf1cb5ff98d45111ec6943e19a79a2837fd
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2013 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB 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.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 /* Standard random generator is slow. For FS testing we need just some
20 garbage files, we don't need them to be high-quality random.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <time.h>
26 #include <sys/time.h>
28 static unsigned long long buffer[1048576];
30 int
31 main (int argc, char **argv)
33 unsigned long long high = 0, low = 1;
34 unsigned long i, j;
35 unsigned long long cnt = strtoull (argv[1], 0, 0);
36 struct timeval tv;
37 gettimeofday (&tv, NULL);
38 high = tv.tv_sec;
39 low = tv.tv_usec;
40 if (!high)
41 high = 1;
42 if (!low)
43 low = 2;
45 for (j = 0; j < (cnt + sizeof (buffer) - 1) / sizeof (buffer); j++)
47 for (i = 0; i < sizeof (buffer) / sizeof (buffer[0]); i += 2)
49 int c1 = 0, c2 = 0;
50 buffer[i] = low;
51 buffer[i+1] = high;
52 if (low & (1ULL << 63))
53 c1 = 1;
54 low <<= 1;
55 if (high & (1ULL << 63))
56 c2 = 1;
57 high = (high << 1) | c1;
58 if (c2)
59 low ^= 0x87;
61 if (sizeof (buffer) < cnt - sizeof (buffer) * j)
62 fwrite (buffer, 1, sizeof (buffer), stdout);
63 else
64 fwrite (buffer, 1, cnt - sizeof (buffer) * j, stdout);
66 return 0;