Implement -o support for fallocate(1)

This commit is contained in:
sin 2013-09-01 17:57:59 +01:00
parent c4315c880a
commit 2ca69a77fb

View File

@ -9,19 +9,22 @@
static void
usage(void)
{
eprintf("usage: %s -l length file\n", argv0);
eprintf("usage: %s [-o offset] -l length file\n", argv0);
}
int
main(int argc, char *argv[])
{
int fd;
long size;
off_t size = 0, offset = 0;
ARGBEGIN {
case 'l':
size = estrtol(EARGF(usage()), 10);
break;
case 'o':
offset = estrtol(EARGF(usage()), 10);
break;
default:
usage();
} ARGEND;
@ -33,7 +36,7 @@ main(int argc, char *argv[])
if (fd < 0)
eprintf("open %s:", argv[0]);
if (posix_fallocate(fd, 0, size) < 0)
if (posix_fallocate(fd, offset, size) < 0)
eprintf("posix_fallocate:");
close(fd);