common/attr: set MAX_ATTR values correctly for NFS
[xfstests-dev.git] / src / fill.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <errno.h>
11
12 /*
13  * fill pathname key nbyte
14  *
15  * use key to seed random number generator so data is deterministic
16  *
17  * lines are at most 72 bytes long so diff(1) does not choke
18  */
19
20 int
21 main(int argc, char **argv)
22 {
23     FILE                *f;
24     unsigned int        seed;
25     long                i;
26     int                 nbyte;
27     char                *hdr;
28     char                *hp;
29     char                c;
30
31     /* quick and dirty, no args checking */
32     if ((f = fopen(argv[1], "w")) == NULL) {
33         fprintf(stderr, "fill: cannot create \"%s\": %s\n", argv[1], strerror(errno));
34         exit(1);
35     }
36     seed = 0;
37     i = 0;
38     while (argv[2][i]) {
39         seed <<= 8;
40         seed |= argv[2][i];
41         i++;
42     }
43     srand(seed);
44
45     nbyte = atoi(argv[3]);
46
47     /*
48      * line format
49      *
50      * byte offset @ start of this line XXXXXXXXXXXX
51      * test iteration number XXXX
52      * key (usually file name) argv[2]
53      * random bytes to fill the line
54      */
55
56     hdr = (char *)malloc(12+1+4+1+strlen(argv[2])+1+1);
57     sprintf(hdr, "%012ld %04d %s ", (long int)0, 0, argv[2]);
58     hp = hdr;
59
60     for (i = 0; i < nbyte-1; i++) {
61         if (*hp) {
62             c = *hp;
63             hp++;
64         }
65         else if ((i % 72) == 71)
66             c = '\n';
67         else
68             c = 32+(rand() % (128-32));
69         fputc(c, f);
70         if (c == '\n') {
71             hp = hdr;
72             sprintf(hdr, "%012ld %04d %s ", i+1, 0, argv[2]);
73         }
74     }
75     fputc('\n', f);
76
77     exit(0);
78 }