mirror of
git://git.suckless.org/ubase
synced 2024-12-24 23:52:34 +00:00
Add fallocate(1)
This commit is contained in:
parent
19992672a5
commit
0f9fd144b7
1
Makefile
1
Makefile
@ -19,6 +19,7 @@ SRC = \
|
||||
clear.c \
|
||||
df.c \
|
||||
dmesg.c \
|
||||
fallocate.c \
|
||||
free.c \
|
||||
halt.c \
|
||||
insmod.c \
|
||||
|
41
fallocate.c
Normal file
41
fallocate.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user