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