1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file repeat.c
4 /// \brief Repeats given string given times
5 ///
6 /// This program can be useful when debugging run-length encoder in
7 /// the Subblock filter, especially the condition when repeat count
8 /// doesn't fit into 28-bit integer.
9 //
10 // Author: Lasse Collin
11 //
12 // This file has been put into the public domain.
13 // You can do whatever you want with this file.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16
17 #include "sysdefs.h"
18 #include <stdio.h>
19
20
21 int
22 main(int argc, char **argv)
23 {
24 if (argc != 3) {
25 fprintf(stderr, "Usage: %s COUNT STRING\n", argv[0]);
26 exit(1);
27 }
28
29 unsigned long long count = strtoull(argv[1], NULL, 10);
30 const size_t size = strlen(argv[2]);
31
32 while (count-- != 0)
33 fwrite(argv[2], 1, size, stdout);
34
35 return !!(ferror(stdout) || fclose(stdout));
36 }