1*286ef713SPaul Dagnelie /*
2*286ef713SPaul Dagnelie * This file and its contents are supplied under the terms of the
3*286ef713SPaul Dagnelie * Common Development and Distribution License ("CDDL"), version 1.0.
4*286ef713SPaul Dagnelie * You may only use this file in accordance with the terms of version
5*286ef713SPaul Dagnelie * 1.0 of the CDDL.
6*286ef713SPaul Dagnelie *
7*286ef713SPaul Dagnelie * A full copy of the text of the CDDL should have accompanied this
8*286ef713SPaul Dagnelie * source. A copy of the CDDL is also available via the Internet at
9*286ef713SPaul Dagnelie * http://www.illumos.org/license/CDDL.
10*286ef713SPaul Dagnelie */
11*286ef713SPaul Dagnelie
12*286ef713SPaul Dagnelie /*
13*286ef713SPaul Dagnelie * Copyright (c) 2016 by Delphix. All rights reserved.
14*286ef713SPaul Dagnelie */
15*286ef713SPaul Dagnelie
16*286ef713SPaul Dagnelie #include <stdio.h>
17*286ef713SPaul Dagnelie #include <stdlib.h>
18*286ef713SPaul Dagnelie #include <fcntl.h>
19*286ef713SPaul Dagnelie #include <string.h>
20*286ef713SPaul Dagnelie #include <errno.h>
21*286ef713SPaul Dagnelie #include <unistd.h>
22*286ef713SPaul Dagnelie #include <sys/param.h>
23*286ef713SPaul Dagnelie
24*286ef713SPaul Dagnelie #define MAX_INT_LENGTH 10
25*286ef713SPaul Dagnelie
26*286ef713SPaul Dagnelie static void
usage(char * msg,int exit_value)27*286ef713SPaul Dagnelie usage(char *msg, int exit_value)
28*286ef713SPaul Dagnelie {
29*286ef713SPaul Dagnelie (void) fprintf(stderr, "mkfiles basename max_file [min_file]\n");
30*286ef713SPaul Dagnelie (void) fprintf(stderr, "%s\n", msg);
31*286ef713SPaul Dagnelie exit(exit_value);
32*286ef713SPaul Dagnelie }
33*286ef713SPaul Dagnelie
34*286ef713SPaul Dagnelie int
main(int argc,char ** argv)35*286ef713SPaul Dagnelie main(int argc, char **argv)
36*286ef713SPaul Dagnelie {
37*286ef713SPaul Dagnelie unsigned int numfiles = 0;
38*286ef713SPaul Dagnelie unsigned int first_file = 0;
39*286ef713SPaul Dagnelie if (argc < 3 || argc > 4)
40*286ef713SPaul Dagnelie usage("Invalid number of arguments", -1);
41*286ef713SPaul Dagnelie
42*286ef713SPaul Dagnelie if (sscanf(argv[2], "%u", &numfiles) != 1)
43*286ef713SPaul Dagnelie usage("Invalid maximum file", -2);
44*286ef713SPaul Dagnelie
45*286ef713SPaul Dagnelie if (argc == 4 && sscanf(argv[3], "%u", &first_file) != 1)
46*286ef713SPaul Dagnelie usage("Invalid first file", -3);
47*286ef713SPaul Dagnelie
48*286ef713SPaul Dagnelie if (numfiles < first_file)
49*286ef713SPaul Dagnelie usage("First file larger than last file", -3);
50*286ef713SPaul Dagnelie
51*286ef713SPaul Dagnelie char buf[MAXPATHLEN];
52*286ef713SPaul Dagnelie for (unsigned int i = first_file; i <= numfiles; i++) {
53*286ef713SPaul Dagnelie int fd;
54*286ef713SPaul Dagnelie (void) snprintf(buf, MAXPATHLEN, "%s%u", argv[1], i);
55*286ef713SPaul Dagnelie if ((fd = open(buf, O_CREAT | O_EXCL, O_RDWR)) == -1) {
56*286ef713SPaul Dagnelie (void) fprintf(stderr, "Failed to create %s %s\n", buf,
57*286ef713SPaul Dagnelie strerror(errno));
58*286ef713SPaul Dagnelie return (-4);
59*286ef713SPaul Dagnelie }
60*286ef713SPaul Dagnelie (void) close(fd);
61*286ef713SPaul Dagnelie }
62*286ef713SPaul Dagnelie return (0);
63*286ef713SPaul Dagnelie }
64