summaryrefslogtreecommitdiffstats
path: root/tests/bugs/distribute/bug-860663.c
blob: bee4e7d40b1938726b224b77f1122a60c2b5b996 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <err.h>
#include <sys/param.h>

int
main(argc, argv)
        int argc;
        char **argv;
{
        char *basepath;
        char path[MAXPATHLEN + 1];
        unsigned int count;
        int i, fd;

        if (argc != 3)
                errx(1, "usage: %s path count", argv[0]);

        basepath = argv[1];
        count = atoi(argv[2]);

        if (count > 999999)
                errx(1, "count too big");

        if (strlen(basepath) > MAXPATHLEN - 6)
                errx(1, "path too long");

        for (i = 0; i < count; i++) {
                (void)sprintf(path, "%s%06d", basepath, i);

                fd = open(path, O_CREAT|O_RDWR, 0644);
                if (fd == -1)
                        err(1, "create %s failed", path);

                if (close(fd) != 0)
                        warn("close %s failed", path);
        }

        return 0;
}