view toys/other/fallocate.c @ 1539:3e85af1f7e22 draft

First batch of sed tests. Only good for TEST_HOST=1 at the moment because the test infrastructure itself depends on sed, so if an unfinished sed is in the $PATH it goes boing. But hey, corner cases! I have... more.
author Rob Landley <rob@landley.net>
date Wed, 29 Oct 2014 18:44:33 -0500
parents 5ec6582aac50
children
line wrap: on
line source

/* fallocate.c - Preallocate space to a file
 *
 * Copyright 2013 Felix Janda <felix.janda@posteo.de>
 *
 * No standard

USE_FALLOCATE(NEWTOY(fallocate, ">1l#|", TOYFLAG_USR|TOYFLAG_BIN))

config FALLOCATE
  bool "fallocate"
  depends on TOYBOX_FALLOCATE
  default y
  help
    usage: fallocate [-l size] file

    Tell the filesystem to allocate space for a file.
*/

#define FOR_fallocate
#include "toys.h"

GLOBALS(
  long size;
)

void fallocate_main(void)
{
  int fd = xcreate(*toys.optargs, O_RDWR | O_CREAT, 0644);
  if (posix_fallocate(fd, 0, TT.size)) error_exit("Not enough space");
  if (CFG_TOYBOX_FREE) close(fd);
}