view toys/other/fallocate.c @ 1189:95ae2805622f draft

Add Szabolcs Nagy's deflate/inflate code from git://git.suckless.org/flate Confirmed with him on IRC it's ok to use under toybox license, glued the files together and hammered square peg into round hole, no other changes yet.
author Rob Landley <rob@landley.net>
date Fri, 31 Jan 2014 06:01:30 -0600
parents d5a1174ff88a
children 2102af52be68
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"
  default n
  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);
}