Martin gave his approval to use GPLv3 with this code.
[rsync/rsync.git] / mkrounding.c
1 /*
2  * A pre-compilation helper program to aid in the creation of rounding.h.
3  *
4  * Copyright (C) 2007 Wayne Davison
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 3 as
8  * published by the Free Software Foundation.
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 along
16  * with this program; if not, visit the http://fsf.org website.
17  */
18
19 #include "rsync.h"
20
21 struct test1 {
22     union file_extras extras1[1];
23     struct {
24 #       include "mkrounding.h"
25     } file;
26 };
27
28 struct test2 {
29     union file_extras extras2[2];
30     struct {
31 #       include "mkrounding.h"
32     } file;
33 };
34
35 struct test4 {
36     union file_extras extras4[4];
37     struct {
38 #       include "mkrounding.h"
39     } file;
40 };
41
42 #define SIZE_TEST(n) (sizeof (struct test ## n) == EXTRA_LEN * n + sizeof (struct file_struct))
43
44  int main(UNUSED(int argc), UNUSED(char *argv[]))
45 {
46     int cnt;
47     if (SIZE_TEST(1))
48         cnt = 0;
49     else if (SIZE_TEST(2))
50         cnt = 1;
51     else if (SIZE_TEST(4))
52         cnt = 3;
53     else {
54         fprintf(stderr, "Unable to determine required file_extras rounding!\n");
55         cnt = 3;
56     }
57     if (cnt)
58         fprintf(stderr, "Rounding file_extras in multiples of %d", cnt + 1);
59     else
60         fprintf(stderr, "No rounding needed for file_extras");
61     fprintf(stderr, " (EXTRA_LEN=%d, FILE_STRUCT_LEN=%d)\n",
62             (int)EXTRA_LEN, (int)FILE_STRUCT_LEN);
63     printf("#define EXTRA_ROUNDING %d\n", cnt);
64     return 0;
65 }