2022-06-27 19:36:56 +02:00
|
|
|
/*
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
UMKa - User-Mode KolibriOS developer tools
|
|
|
|
mkdirrange - make directories with names in range
|
|
|
|
|
|
|
|
Copyright (C) 2018-2019 Ivan Baravy <dunkaist@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2018-05-09 23:08:52 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2018-05-19 17:48:10 +02:00
|
|
|
#include <fcntl.h>
|
2018-05-09 23:08:52 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-11-08 03:22:07 +01:00
|
|
|
unsigned begin, end;
|
|
|
|
int pat_min, pat_max;
|
2018-05-19 17:48:10 +02:00
|
|
|
char *path;
|
2019-11-08 03:22:07 +01:00
|
|
|
if (argc == 6) {
|
2018-05-19 17:48:10 +02:00
|
|
|
path = argv[1];
|
|
|
|
sscanf(argv[2], "%u", &begin);
|
|
|
|
sscanf(argv[3], "%u", &end);
|
2019-11-08 03:22:07 +01:00
|
|
|
sscanf(argv[4], "%i", &pat_min);
|
|
|
|
sscanf(argv[5], "%i", &pat_max);
|
2018-05-19 17:48:10 +02:00
|
|
|
} else {
|
2019-11-08 03:22:07 +01:00
|
|
|
fprintf(stderr, "mkdirrange <directory> <num_begin> <num_end> <pat_min> <pat_max>\n"
|
|
|
|
"pat_min + pat_max <= 244\n");
|
2018-05-09 23:08:52 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2018-05-19 17:48:10 +02:00
|
|
|
int dirfd = open(path, O_DIRECTORY);
|
|
|
|
if (dirfd == -1) {
|
|
|
|
fprintf(stderr, "Can't open %s: %s\n", path, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
char dirname[256];
|
|
|
|
memset(dirname, 'x', 256);
|
2018-05-09 23:08:52 +02:00
|
|
|
|
2018-05-19 17:48:10 +02:00
|
|
|
for(unsigned current = begin; current < end; current++) {
|
|
|
|
int length = sprintf(dirname, "d%10.10u_", current);
|
|
|
|
dirname[length] = 'x';
|
2019-11-08 03:22:07 +01:00
|
|
|
length += pat_min + (current % pat_max);
|
2018-05-19 17:48:10 +02:00
|
|
|
dirname[length] = '\0';
|
|
|
|
if(mkdirat(dirfd, dirname, 0755)) {
|
|
|
|
fprintf(stderr, "Can't mkdir %s: %s\n", dirname, strerror(errno));
|
2018-05-09 23:08:52 +02:00
|
|
|
exit(1);
|
2018-05-19 17:48:10 +02:00
|
|
|
} else {
|
|
|
|
dirname[length] = 'x';
|
2018-05-09 23:08:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|