userland/c/infinite_loop.c: allow passing a max loop parameter

Useful to quickly obtain a simple variable size content.
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-06-13 00:00:00 +00:00
parent 9dd63f6f54
commit 647eacf13a

View File

@@ -13,12 +13,19 @@
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {
uintmax_t i, j, period; uintmax_t i, j, period, max;
int max_given;
if (argc > 1) { if (argc > 1) {
period = strtoumax(argv[1], NULL, 10); period = strtoumax(argv[1], NULL, 10);
} else { } else {
period = 100000000; period = 100000000;
} }
if (argc > 2) {
max = strtoumax(argv[2], NULL, 10);
max_given = 1;
} else {
max_given = 0;
}
i = 0; i = 0;
j = 0; j = 0;
while (1) { while (1) {
@@ -27,5 +34,7 @@ int main(int argc, char **argv) {
printf("%ju\n", j); printf("%ju\n", j);
j++; j++;
} }
if (max_given && i == max)
break;
} }
} }