2013-08-16 10:14:55 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <sys/stat.h>
|
2014-06-30 18:03:41 +00:00
|
|
|
|
2013-08-16 10:14:55 +00:00
|
|
|
#include <fcntl.h>
|
2015-09-10 22:27:29 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdint.h>
|
2013-08-16 10:14:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-06-30 18:03:41 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2013-08-16 10:14:55 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-09-10 22:27:29 +00:00
|
|
|
eprintf("usage: %s [-o num] -l num file ...\n", argv0);
|
2013-08-16 10:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2015-09-10 22:27:29 +00:00
|
|
|
int fd, ret = 0;
|
2013-09-01 16:57:59 +00:00
|
|
|
off_t size = 0, offset = 0;
|
2013-08-16 10:14:55 +00:00
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case 'l':
|
2015-09-10 22:27:29 +00:00
|
|
|
size = estrtonum(EARGF(usage()), 1, MIN(LLONG_MAX, SIZE_MAX));
|
2013-08-16 10:14:55 +00:00
|
|
|
break;
|
2013-09-01 16:57:59 +00:00
|
|
|
case 'o':
|
2015-09-10 22:27:29 +00:00
|
|
|
offset = estrtonum(EARGF(usage()), 0, MIN(LLONG_MAX, SIZE_MAX));
|
2013-09-01 16:57:59 +00:00
|
|
|
break;
|
2013-08-16 10:14:55 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
2015-09-10 22:27:29 +00:00
|
|
|
if (!argc || !size)
|
2013-08-16 10:14:55 +00:00
|
|
|
usage();
|
|
|
|
|
2015-09-10 22:27:29 +00:00
|
|
|
for (; *argv; argc--, argv++) {
|
|
|
|
if ((fd = open(*argv, O_RDWR | O_CREAT, 0644)) < 0) {
|
|
|
|
weprintf("open %s:", *argv);
|
|
|
|
ret = 1;
|
|
|
|
} else if (posix_fallocate(fd, offset, size) < 0) {
|
|
|
|
weprintf("posix_fallocate %s:", *argv);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd >= 0 && close(fd) < 0) {
|
|
|
|
weprintf("close %s:", *argv);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-08-16 10:14:55 +00:00
|
|
|
}
|