2013-08-16 10:14:55 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2013-09-01 16:57:59 +00:00
|
|
|
eprintf("usage: %s [-o offset] -l length file\n", argv0);
|
2013-08-16 10:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd;
|
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':
|
|
|
|
size = estrtol(EARGF(usage()), 10);
|
|
|
|
break;
|
2013-09-01 16:57:59 +00:00
|
|
|
case 'o':
|
|
|
|
offset = estrtol(EARGF(usage()), 10);
|
|
|
|
break;
|
2013-08-16 10:14:55 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc != 1 || !size)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
fd = open(argv[0], O_RDWR | O_CREAT, 0644);
|
|
|
|
if (fd < 0)
|
|
|
|
eprintf("open %s:", argv[0]);
|
|
|
|
|
2013-09-01 16:57:59 +00:00
|
|
|
if (posix_fallocate(fd, offset, size) < 0)
|
2013-08-16 10:14:55 +00:00
|
|
|
eprintf("posix_fallocate:");
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|