1
0
mirror of git://git.suckless.org/ubase synced 2024-12-24 23:52:34 +00:00

Add fallocate(1)

This commit is contained in:
sin 2013-08-16 11:14:55 +01:00
parent 19992672a5
commit 0f9fd144b7
2 changed files with 42 additions and 0 deletions

View File

@ -19,6 +19,7 @@ SRC = \
clear.c \
df.c \
dmesg.c \
fallocate.c \
free.c \
halt.c \
insmod.c \

41
fallocate.c Normal file
View File

@ -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;
}