ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit 0f9fd144b79af32ad2e9d08ae4495ac6edf21b47
parent 19992672a544fb0d434fe25ffb881a90b16e1fe6
Author: sin <sin@2f30.org>
Date:   Fri, 16 Aug 2013 11:14:55 +0100

Add fallocate(1)

Diffstat:
MMakefile | 1+
Afallocate.c | 41+++++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -19,6 +19,7 @@ SRC = \ clear.c \ df.c \ dmesg.c \ + fallocate.c \ free.c \ halt.c \ insmod.c \ diff --git a/fallocate.c b/fallocate.c @@ -0,0 +1,41 @@ +/* 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) +{ + eprintf("usage: %s -l length file\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + int fd; + long size; + + ARGBEGIN { + case 'l': + size = estrtol(EARGF(usage()), 10); + break; + 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]); + + if (posix_fallocate(fd, 0, size) < 0) + eprintf("posix_fallocate:"); + + close(fd); + return 0; +}