]> icculus.org git repositories - icculus/xz.git/blob - debug/repeat.c
849f7b76ff985541e3e074f325f10006caff40dc
[icculus/xz.git] / debug / repeat.c
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 //  Copyright (C) 2008 Lasse Collin
11 //
12 //  This library is free software; you can redistribute it and/or
13 //  modify it under the terms of the GNU Lesser General Public
14 //  License as published by the Free Software Foundation; either
15 //  version 2.1 of the License, or (at your option) any later version.
16 //
17 //  This library is distributed in the hope that it will be useful,
18 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 //  Lesser General Public License for more details.
21 //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "sysdefs.h"
25 #include <stdio.h>
26
27
28 int
29 main(int argc, char **argv)
30 {
31         if (argc != 3) {
32                 fprintf(stderr, "Usage: %s COUNT STRING\n", argv[0]);
33                 exit(1);
34         }
35
36         unsigned long long count = strtoull(argv[1], NULL, 10);
37         const size_t size = strlen(argv[2]);
38
39         while (count-- != 0)
40                 fwrite(argv[2], 1, size, stdout);
41
42         return !!(ferror(stdout) || fclose(stdout));
43 }